RE: [PHP] Check contents of variable
You could also try: if(! ereg('^http://', $url)) $url = 'http://' . $url; -JAson Garber At 11:15 PM 11/20/2001 +0100, Daniel Alsén wrote: > > How about: > > > > if (substr($url,0,7) <> "http://";) > > $url = "http://"; . $url; > >Thanks! > >That´s just the function i am looking for. I looked it up in the manual. >Correct me if i am wrong - if i don´t set the second parameter in substr it >just continues to read until the variable is finished? If i set it to 7 (as >above) it stops reading after 7 characters? > >- Daniel > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] >To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Check contents of variable
Correct, the third parameter is for the number of characters to read, nothing means entire string. Function details can be found here: http://download.php.net/manual/en/function.substr.php > > How about: > > > > if (substr($url,0,7) <> "http://";) > > $url = "http://"; . $url; > > Thanks! > > That´s just the function i am looking for. I looked it up in the manual. > Correct me if i am wrong - if i don´t set the second parameter in substr it > just continues to read until the variable is finished? If i set it to 7 (as > above) it stops reading after 7 characters? > > - Daniel > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Check contents of variable
> How about: > > if (substr($url,0,7) <> "http://";) > $url = "http://"; . $url; Thanks! That´s just the function i am looking for. I looked it up in the manual. Correct me if i am wrong - if i don´t set the second parameter in substr it just continues to read until the variable is finished? If i set it to 7 (as above) it stops reading after 7 characters? - Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Check contents of variable
How about: if (substr($url,0,7) <> "http://";) $url = "http://"; . $url; > Hi, > > which function would i use to check if a certain value is in the contents of > a variable? > > I have a form where the users submits url's. I need the url with http:// in > the beginning. Since there is more data after the http:// i can´t just do a > simple if-statement. So what do i do? > > After i determined if there is a http:// in the variable or not i guess i > just have to $url = "http://"; + $url; (?)... > > Regards > # Daniel Alsén| www.mindbash.com # > # [EMAIL PROTECTED] | +46 704 86 14 92 # > # ICQ: 63006462 | # > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Check contents of variable
Hi, which function would i use to check if a certain value is in the contents of a variable? I have a form where the users submits url's. I need the url with http:// in the beginning. Since there is more data after the http:// i can´t just do a simple if-statement. So what do i do? After i determined if there is a http:// in the variable or not i guess i just have to $url = "http://"; + $url; (?)... Regards # Daniel Alsén| www.mindbash.com # # [EMAIL PROTECTED] | +46 704 86 14 92 # # ICQ: 63006462 | # -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]