Jump to content

Need help with str_replace wildstring


vick22

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/261896-need-help-with-str_replace-wildstring/
Share on other sites

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;

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.