Welcome to WebmasterWorld Guest from 54.196.243.192

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)

Full Member

10+ Year Member

joined:Mar 19, 2001
posts:220
votes: 0


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)

Full Member

10+ Year Member

joined:Mar 19, 2001
posts:220
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Aug 8, 2001
posts:926
votes: 0


> 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)

Full Member

10+ Year Member

joined:Mar 19, 2001
posts:220
votes: 0


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)

Senior Member

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

joined:Mar 15, 2002
posts:6807
votes: 0


/^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) ;)