note 53804 deleted from function.trim by sean
| From: | sean@php.net | Date: | Mon, 13 Jun 2005 23:47:34 +0000 |
| Subject: | note 53804 deleted from function.trim by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-90385@lists.php.net to get a copy of this message | ||
Note Submitter: bpgordon at gmail dot com
Reason: useless example
----
Er, make that:
Don't use trim to strip the trailing / off of relative URLs!
<?php
trim($url, "/");
?>
It will also strip the / from the beginning of the URL. Instead, use this function:
<?php
function trimrelativeurl($url) {
$urlarry = preg_split('//', $url, -1, PREG_SPLIT_NO_EMPTY);
foreach ($urlarry as $key => $val) {
if ($val == "/") $lastslash = $key;
}
if ($lastslash+1 == strlen($url))
$url = substr($url, 0, strlen($url)-1);
return $url;
}
?>