Welcome to WebmasterWorld Guest from 23.22.220.37

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

preg replace help

     
2:08 pm on Jul 23, 2009 (gmt 0)

Full Member

10+ Year Member

joined:Aug 9, 2005
posts:240
votes: 0


I want to strip out the following in a string:

[blah.com...]

Basically the URL followed by 4 0-9A-Za-z

I have this:

preg_replace('/http:\/\/blah\.com\/[0-9A-Za-z]{4}/', '', $text);

But it doesn't quite work. I still want it to show URL's like [blah.com...] and [blah.com...]

Any ideas?

2:29 pm on July 23, 2009 (gmt 0)

Full Member

10+ Year Member

joined:Aug 9, 2005
posts:240
votes: 0


I actually want to extract the 'aBc4' first, store it in a variable, and then remove it from the string
3:09 am on July 24, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 22, 2005
posts:185
votes: 0


idea:
if (preg_match('/(http:\/\/[^\/]+)\/([0-9A-Za-z]{4})/', $text, $match)) 
{
$url = $match[1];
$extract = $match[2];
}
else
{
$url = $text;
}