Jump to content

str_replace() with wildcard value


monkeypaw201

Recommended Posts

I have a snippet of code from my page here:

 

$filtered2 = str_replace(" nm</td><td class=results width=50 style='align:center'><a href='?site=pl&show=700579c68127f8f25825b1efb8c2f56d' class='link'>details</a></td></tr>","",$sort[1]);

 

But the &show=<value> is always different, yet i need to replace that string regardless...

 

How can this be done? (I prefer code and an explanation if possible)

Link to comment
https://forums.phpfreaks.com/topic/154283-str_replace-with-wildcard-value/
Share on other sites

<?php
$string = " nm</td><td class=results width=50 style='align:center'><a href='?site=pl&show=700579c68127f8f25825b1efb8c2f56d' class='link'>details</a></td></tr> asdfasf";
$filtered2 = preg_replace("~ nm.*?&show=(.*?)' .*?</tr>~is", "", $string);
var_dump(htmlentities($filtered2));
die();
?>

 

I would suggest going with preg_replace instead.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.