homepage Welcome to WebmasterWorld Guest from 54.166.116.36
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
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
mdharrold

10+ Year Member



 
Msg#: 393 posted 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;}
else
{$url = "http://$url";}

So what would be the PHP equivalent?

 

mdharrold

10+ Year Member



 
Msg#: 393 posted 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].

gethan

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 393 posted 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.

mdharrold

10+ Year Member



 
Msg#: 393 posted 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.

DrDoc

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



 
Msg#: 393 posted 10:02 am on Mar 16, 2002 (gmt 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) ;)

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