preg_replace URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psxmetal
Forum Newbie
Posts: 6
Joined: Sun May 31, 2009 11:25 pm

preg_replace URL

Post 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!?
Last edited by psxmetal on Thu Jun 04, 2009 5:33 pm, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: preg_replace URL

Post by requinix »

The irony here is killing me :D

Have you tried Google yet?
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: preg_replace URL

Post 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);
 
psxmetal
Forum Newbie
Posts: 6
Joined: Sun May 31, 2009 11:25 pm

Re: preg_replace URL

Post 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
psxmetal
Forum Newbie
Posts: 6
Joined: Sun May 31, 2009 11:25 pm

Re: preg_replace URL

Post by psxmetal »

tasairis wrote:The irony here is killing me :D

Have you tried Google yet?

i have =( maybe im not typing in the correct term
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: preg_replace URL

Post 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.
psxmetal
Forum Newbie
Posts: 6
Joined: Sun May 31, 2009 11:25 pm

Re: preg_replace URL

Post 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.
Post Reply