PHP preg_replace Help?

$url = "google.com"; if(!preg_match("/^https/i",$url)) $url = "$url.

So, how can I transform google. Com into google.com If you just need to prefix something then it's simple: $url = '' . $url; If the text "google.Com" is in some larger text, you may be able to use a regular expression.

It's difficult to offer specific advice since I don't know the structure of the larger text, but maybe something along the lines of: preg_replace('/(.*\.(com|net|org))/', '\1', $url); However, if the src="google. Com" instead of "google.com" it will not work. Your assumption here is that iframes "work" at all under any condition.

Iframes ... shiver ...

There are better ways to do this, but this will work: if(!preg_match("#^http:\/\/#", $url)) { $url = "http://". $url; }.

$url = '' . $url; the simpliest way possible :o.

Like so: $url = 'google. Com'; if (!preg_match('#^#', $url)) { $url = ''. $url; }.

Just for fun, here's one that uses just preg_replace by taking advantage of a negative lookahead. However, I agree with the other solutions here, that it is probably best to just to a preg_match and then a string concatenation. $url = preg_replace('#^(?!

Https? ://)#', '', $url).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions