Page 1 of 1
preg_replace URL
Posted: Thu Jun 04, 2009 4:13 pm
by psxmetal
hey anyone can help me im not very good with matching stuff. need to check it out one day.
basically i need to check a string if theres a url in it to change
http://www.xxx.com to
http://www.xxx.com
Code: Select all
$text = preg_replace('#(<!http://)(www\.[a-z0-9;/?:@=&$_.+!*\'(),~%-]+\.com)#', "http://$1", $text);
not worry =( anyone can help out!?
Re: preg_replace URL
Posted: Thu Jun 04, 2009 4:52 pm
by requinix
The irony here is killing me
Have you tried Google yet?
Re: preg_replace URL
Posted: Thu Jun 04, 2009 5:02 pm
by mikemike
Aren't those URL's identical?
In anycase:
Code: Select all
// String to find
$search_string = 'http://www.yahoo.com';
// Stirng to replace it with
$replace_string = 'http://www.google.com';
// Run the search
str_replace($search_string, $replace_string, $your_original_string);
Re: preg_replace URL
Posted: Thu Jun 04, 2009 5:14 pm
by psxmetal
mikemike wrote:Aren't those URL's identical?
In anycase:
Code: Select all
// String to find
$search_string = 'http://www.yahoo.com';
// Stirng to replace it with
$replace_string = 'http://www.google.com';
// Run the search
str_replace($search_string, $replace_string, $your_original_string);
thats funny basically i put www. only and it fixed the url to have http:// thats what i want! lol
Re: preg_replace URL
Posted: Thu Jun 04, 2009 5:14 pm
by psxmetal
tasairis wrote:The irony here is killing me
Have you tried Google yet?
i have =( maybe im not typing in the correct term
Re: preg_replace URL
Posted: Thu Jun 04, 2009 5:51 pm
by mikemike
I think it's because your original post is very different from the one you've edited it to, which is now going to confuse everyone.
Re: preg_replace URL
Posted: Thu Jun 04, 2009 6:07 pm
by psxmetal
mikemike wrote:I think it's because your original post is very different from the one you've edited it to, which is now going to confuse everyone.
how is it so different, the only difference is i put the code iv been messing with.