homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

if x contains y in php
simple in perl, can't find good php site

 9:42 pm on Mar 7, 2002 (gmt 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;}
{$url = "http://$url";}

So what would be the PHP equivalent?



 10:29 pm on Mar 7, 2002 (gmt 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)

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

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)


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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved