2010-11-21 4 views
0

PHP 정규 표현식을 이해하는 데 도움이됩니다. 이 문자열을 가지고 :PHP regexp : URL 부분을 텍스트 문자열로 바꾸기

내가 예를 product_list_replaced

를 들어, imagecache/<img> 태그 내에 /SOME_TEXT와 사이에 위치하고 product_list이 어떤 도움이

감사 교체해야

<a href="/kop/product/acer-timeline-5810tg-944g50mi" class="imagecache imagecache-product_list imagecache-linked imagecache-product_list_linked"><img src="http://localhost/kop/sites/default/files/imagecache/product_list/Acer-Timeline-1.jpg" alt="Acer As Timeline 5810TG-944G50Mi" title="Acer As Timeline 5810TG-944G50Mi" class="imagecache imagecache-product_list" width="100" height="100" /></a> 

감사합니다.

답변

0

방금하면

$text = '<a href="/kop/product/acer-timeline-5810tg-944g50mi" class="imagecache imagecache-product_list imagecache-linked imagecache-product_list_linked"><img src="http://localhost/kop/sites/default/files/imagecache/product_list/Acer-Timeline-1.jpg" alt="Acer As Timeline 5810TG-944G50Mi" title="Acer As Timeline 5810TG-944G50Mi" class="imagecache imagecache-product_list" width="100" height="100" /></a>'; 

$new = '<img>product_list_replaced</img>'; 
$match = 'imagecache/'; 

$newstr= str_replace($match, $replace, $text); 

당신이 정기적으로 expresions에 관심이 있다면

this site

HTH의 모습을 : 모자 str_replace()를 사용하는 것이 더 쉽습니다, 당신은이 방법을 수행 할 수 있습니다!