note 100166 deleted from function.stripos by danbrown
| From: | danbrown@php.net | Date: | Wed, 29 Jun 2011 18:51:08 +0000 |
| Subject: | note 100166 deleted from function.stripos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181067@lists.php.net to get a copy of this message | ||
Note Submitter: guanfenglin at gmail dot com
----
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
<?php
$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:
<?php
$url = (stripos($url,"http")===false) ? "http".$url : $url;
?>
James Lin