Forum Moderators: coopster

Message Too Old, No Replies

testing to see if a string starts with http://

string test

         

newb2seo

9:24 pm on Jun 26, 2009 (gmt 0)

10+ Year Member



Hi.
I am trying to check if a string is a full url.
And if not, to fix it.

I have a series of strings... some are full urls starting with http.

others are just like ../folder/image.gif

while others are "images/here.gif" etc

I'm thinking I need to use something like preg_match?

But I'm not so familiar with it.

An example I found is like
#===============================================


<?php
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
?>


#===============================================

I know the carrot sign (up arrow) needs to be used to check stuff at the beginning.

Any help is appreciated.

Thanks.
-J

g1smd

10:10 pm on Jun 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Carrot?

LOL.

It's a

caret
, like this ^

^http://

newb2seo

12:53 am on Jun 27, 2009 (gmt 0)

10+ Year Member



:)
Yes I know. I don't know how to spell it. :)

Do you know what the regex would look like for preg_match?
In order to check content for that?

FourDegreez

4:07 pm on Jun 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use this one, which covers most URLs. It could be improved further or edited for your needs, but here it is:

'/(http:\/\/¦https:\/\/¦ftp:\/\/)([a-z0-9\.\/,_-]+)/i'