vick22 Posted May 1, 2012 Share Posted May 1, 2012 Hi, I have the following text: London, May 1: Hi there I am trying to remove everything till ':' The desired output is %20Hi%20there I did this - $np2 = "London, May 1: Hi there"; $i = array('-',' ','(.*):'); $j = array('','%20',''); $np = str_replace($i, $j, $np2); echo $np; I am unable to remove London, May 1: Note: The word "London" could be anything, so I am trying to get a wildcard. Quote Link to comment https://forums.phpfreaks.com/topic/261896-need-help-with-str_replace-wildstring/ Share on other sites More sharing options...
Jessica Posted May 1, 2012 Share Posted May 1, 2012 You'll need to use regular expressions. Quote Link to comment https://forums.phpfreaks.com/topic/261896-need-help-with-str_replace-wildstring/#findComment-1341927 Share on other sites More sharing options...
vick22 Posted May 1, 2012 Author Share Posted May 1, 2012 I tried that too but was unable to get it going. Can you help me out plz? Quote Link to comment https://forums.phpfreaks.com/topic/261896-need-help-with-str_replace-wildstring/#findComment-1341930 Share on other sites More sharing options...
Jessica Posted May 1, 2012 Share Posted May 1, 2012 I can't because I am horrible at regex. Hopefully a mod will come and move this thread to the regex board. If you already tried, you should post what you did try so people can help you fix it. Quote Link to comment https://forums.phpfreaks.com/topic/261896-need-help-with-str_replace-wildstring/#findComment-1341931 Share on other sites More sharing options...
PFMaBiSmAd Posted May 1, 2012 Share Posted May 1, 2012 If you only want the part of the string after the :, there's no point in worrying about what is before the :, unless you are specifically trying to find just that pattern among a bunch of content, but you would have probably shown us if that was the case. <?php $string = "London, May 1: Hi there"; list(,$string) = explode(':',$string); $string = str_replace(' ','%20',$string); echo $string; Quote Link to comment https://forums.phpfreaks.com/topic/261896-need-help-with-str_replace-wildstring/#findComment-1341934 Share on other sites More sharing options...
Jessica Posted May 1, 2012 Share Posted May 1, 2012 That is a great point, I guess I didn't read the initial question well enough, because you're right as it's written you don't need regex. Quote Link to comment https://forums.phpfreaks.com/topic/261896-need-help-with-str_replace-wildstring/#findComment-1341936 Share on other sites More sharing options...
vick22 Posted May 1, 2012 Author Share Posted May 1, 2012 Perfect!! Works very nice. Quote Link to comment https://forums.phpfreaks.com/topic/261896-need-help-with-str_replace-wildstring/#findComment-1341952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.