Reputation: 8970
I am trying to remove a specific URL from a text string. I have it working for the most part but I need to include both http
or https
versions of the link.
$link = '<a href="http://example.com/Tool/document.php?id=208" target="_BLANK">Document Requirementsd</a>';
$result = preg_replace('/<a href=\"http:\/\/' . $_SERVER["SERVER_NAME"] . '\/Tool\/document.php\?id=(.*?)\">(.*?)<\/a>/', "\\2", htmlspecialchars_decode($html));
Whats the best way to make sure that both http and https links are stripped?
Upvotes: 1
Views: 235
Reputation: 413
So you need
$link = '<a href="http://example.com/Tool/document.php?id=208" target="_BLANK">Document Requirementsd</a>';
$link = '<a href="https://example.com/Tool/document.php?id=208" target="_BLANK">Document Requirementsd</a>';
Right?
You use get the https link by replace assuming http as static
//get primary link always http (we need to create http or https isset func)
$link = '<a href="http://example.com/Tool/document.php?id=208" target="_BLANK">Document Requirementsd</a>';
//making that as https
$https=str_replace('http','https',$link);
//So now you can do whatever you want.
$result = preg_replace('/<a href=\"http:\/\/' . $_SERVER["SERVER_NAME"] . '\/Tool\/document.php\?id=(.*?)\">(.*?)<\/a>/', "\\2", htmlspecialchars_decode($html));
If you want to check if the link is http or https, I can write some more code to find out.
Upvotes: 0