Welcome to WebmasterWorld Guest from 54.205.251.179

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

if x contains y in php

simple in perl, can't find good php site

   
9:42 pm on Mar 7, 2002 (gmt 0)

10+ Year Member



I'm trying to learn PHP. Partly because of the responses in here [webmasterworld.com], partly because I want to.

In perl what I want would be:
if ($url =~ /http/)
{$url = $url;}
else
{$url = "http://$url";}

So what would be the PHP equivalent?

10:29 pm on Mar 7, 2002 (gmt 0)

10+ Year Member



I found a reasonable fix:
if (preg_match ("/http/i", "$url"))
{$url = $url;}
else {$url = "http://$url";}

Found it at zend [zend.com].

11:19 pm on Mar 7, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Perl: $url =~ /http/i
> PHP : preg_match ("/http/i", "$url")

preg - short for perl regular expressions.

What I miss most with php are reg expressions done the perl way ;) I just think that too much typing is involved. But then I had a short stint writing VB and found out what real pain is.

11:27 pm on Mar 7, 2002 (gmt 0)

10+ Year Member



I thought the same thing. Supposedly, PHP is easier to learn. It seems the language that would be easiest to learn would be the one with the least amount of required code.
10:02 am on Mar 16, 2002 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



/^http:\/\//

'cause what if the URL is "www.httpthing.com"?

And, what if the user typed in "http:/www.somesite.com" .. then it wouldn't work anyway ..

(In case you ask, yes, I'm only here to give you a hard time) ;)