Jump to content

Replace part of string


htmanning

Recommended Posts

Hi - newbie to php - I need to search a string and possibly replace part of it.  This is how I would do it in perl:

 

if ($homepage) {
	if ($homepage !~ /http/i) {
		$homepage = "http:\/\/" . $homepage;
	}
}

 

I have a homepage field in the database but sometimes people put the http in, and sometimes they leave it out.  In perl I can figure it out and format accordingly but it doesn't work in PHP.  I'm not sure if the first line even works in PHP.  Maybe if to say something like:

 

if $homepage is not equal to nothing. I'm not sure.

 

Any help would be appreciated.

 

Thanks.

 

 

Link to comment
https://forums.phpfreaks.com/topic/246593-replace-part-of-string/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.