Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-30-2012, 06:12 AM   PM User | #1
catlover
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
catlover is an unknown quantity at this point
How Would I Remove all instances of this?

I want to remove every instance of this that I find:

Ad ID: 12323500

....where "Ad ID: " will always be the same, but the number after it will always be different. It will always be a 8-digit number though.

I'm a php newb and I usually just use str_replace to get rid of stuff I don't want but wasn't sure how to approach it in this situation.

Thank you!!
catlover is offline   Reply With Quote
Old 11-30-2012, 07:38 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,530
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
use preg_replace instead of str_replace so you can use a regular expression.

The following regul;ar expression will match every occurrence of your Ad ID provided that it is followed by an eight digit number

/Ad ID: \d{8}/
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 11-30-2012, 02:29 PM   PM User | #3
catlover
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
catlover is an unknown quantity at this point
Thumbs up

Quote:
Originally Posted by felgall View Post
use preg_replace instead of str_replace so you can use a regular expression.

The following regul;ar expression will match every occurrence of your Ad ID provided that it is followed by an eight digit number

/Ad ID: \d{8}/
Thank you so very much. Worked perfect!!
catlover is offline   Reply With Quote
Reply

Bookmarks

Tags
replace, str_replace

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:07 AM.


Advertisement
Log in to turn off these ads.