2016年7月26日 星期二

[PHP] Regular Expression to URL removed in PHP


Regular Expression to URL removed in PHP


Example:

<?php

    preg_match_all('/<a.*?href=".*?">(.*?)<[\/]a>/', $content,$arr);
    
    $new_content = str_replace($arr[0], $arr[1], $content);
    echo $new_content;


?>

Source:
$content='The author is occupied with handling solutions for quite sometimes and he has years of experience in <br />
<a href="http://www.optimumgroup.com.au/product-details/Outdoor-Dangerous-Goods-Storage/51" rel="nofollow">Outdoor Dangerous Goods Storage</a> and Line Shaft Conveyors. OHS is a premium company for handling <a href="http://www.optimumgroup.com.au/product-details/Line-Shaft-Conveyors/26" rel="nofollow">solutions</a> in Sydney. ';


Result:

$arr





$new_content


The author is occupied with handling solutions for quite sometimes and he has years of experience in 
Outdoor Dangerous Goods Storage and Line Shaft Conveyors. OHS is a premium company for handling solutions in Sydney.

 

沒有留言:

張貼留言