note 100166 added to function.stripos
| From: | guanfenglin at gmail dot com | Date: | Wed, 29 Sep 2010 03:19:20 +0000 |
| Subject: | note 100166 added to function.stripos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172798@lists.php.net to get a copy of this message | ||
Just a friendly hint:
I came across to this scenario, check to see if an URL string contains http, if no then prepend
"http" to the URL string
$url = (stripos($url,"http")==false) ? "http".$url : $url;
now, this will always add the http:// to the URL string even the URL string
already has http
It is because stripos($url,"http") will return false if no http found, and stripos($url,
"http") will return 0 if it is found (being at the start of the string) , and (0==false)
is a true condition
therefore, to fix this problem, we have to use (===) to compare the value type as well:
$url = (stripos($url,"http")===false) ? "http".$url : $url;
James Lin
----
Server IP: 69.147.83.197
Probable Submitter: 210.55.214.5
----
Manual Page -- http://www.php.net/manual/en/function.stripos.php
Edit -- https://master.php.net/note/edit/100166
Del: integrated -- https://master.php.net/note/delete/100166/integrated
Del: useless -- https://master.php.net/note/delete/100166/useless
Del: bad code -- https://master.php.net/note/delete/100166/bad+code
Del: spam -- https://master.php.net/note/delete/100166/spam
Del: non-english -- https://master.php.net/note/delete/100166/non-english
Del: in docs -- https://master.php.net/note/delete/100166/in+docs
Del: other reasons-- https://master.php.net/note/delete/100166
Reject -- https://master.php.net/note/reject/100166
Search -- https://master.php.net/manage/user-notes.php