I need a code snippit to do this
if("http://" is at the begging of the variable $url)
{
do nothing
}
else
{
append » to the beginning of the variable $url
}
SDP2006
12-24-2003, 02:27 AM
<?php
$url = "http://www.codingforums.com";
if(preg_match(/http/, $url)){
echo ""; /*Does Nothing*/
}
else
{
/*What do you mean by - "append » to the beginning of the variable $url"*/
}
?>
What do you mean by - "append » to the beginning of the variable $url"??
Hope this helps.
hmmm I'm not sure if that would work
I want it to check to see if "http://" (<-- the whole thing) is at the beginning of $url and if not, add it
so if $url = http://www.site.com, it's left alone but
if $url = www.anothersite.com, it's changed to http://www.anothersite.com
you could use regex, but i think a simple substr will be more effincient
so
if (substr($url,0,7) != "http://"){
$newurl = "http://" ;
}
$newurl .= $url ;
should do the trick
bcarl314
12-24-2003, 12:19 PM
or
preg_match("/http:\/\//i",$url);
mordred
12-24-2003, 03:12 PM
Better check for
if ( !preg_match("/^http:\/\//i",$url) ) { // etc.
since it's only important to know if "http" is at the beginning of the string, not somewhere else.
Originally posted by raf
you could use regex, but i think a simple substr will be more effincient
so
if (substr($url,0,7) != "http://"){
$newurl = "http://" ;
}
$newurl .= $url ;
should do the trick
That one worked and I modified it just a little bit, just changed it not to use the $newurl variable :)