Jump to content

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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.