Jump to content

check that string has http:// at the start?


Vivid Lust

Recommended Posts

<?php
$string = "test this";
$check = substr($string, 0, 6);

if (strtolower($check) != "http://") {
    echo 'The price is wrong BOB';
}else {
   echo 'ok...';
}
?>

 

substr would be your huckleberry.

 

edit:

Changed 7 to a 6.

$string = "http://www.google.com";
echo (substr($string, 0, 7)=="http://" ? "begins with" : "does not";

 

premiso beat me to it but here's mine anyway.

 

:) Just a correction (I had it wrong in mine) the 7 should be 6, since substr it is 0 based.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.