Jump to content

How do do a str_replace on this?


Jeffro

Recommended Posts

I'm trying to do a string replace on this phrase:  "all 6 news updates" 

 

... keeping in mind that the number 6 could be 30 or 100 or 1000 or whatever...  How do I go about that?  I know how when the text is static but since the number is changing, I dont. 

 

Thanks. 

Link to comment
Share on other sites

You'll want to use regex

$str = "all 6 news updates";
$number = preg_replace('/all (\d+) news updates/', '$1', $str);

echo "Echo the number is: $number";

 

What do you want replace the number with?

 

Actually, I'm not wanting to replace the number.  I want to find all instances of that entire phrase (regardless of the number that I find) and blank it out. 

$description=str_replace('all 6 news updates','',$description)

 

...keeping in mind that the number could be anything, which is why I can't use the code as I've just written it. 

 

Thanks!

Link to comment
Share on other sites

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.