note 25179 added to ref.strings
| From: | d dot gebuehr at ntz dot de | Date: | Fri, 13 Sep 2002 08:25:34 +0000 |
| Subject: | note 25179 added to ref.strings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-36624@lists.php.net to get a copy of this message | ||
I've written a small function, which extracts all positions of a given charakter from a string.
It may be useful for example to modify html-tags with not known values. (It's used to get rid
of class-arguments and mso-styles while importing MS-Word-Documents):
function charpos($searchstring,$delimiter) {
global $positions;
global $search_found;
if (strpos($searchstring,$delimiter) === FALSE) {
$search_found=0;
}
else {
$search_found=1;
$searchlen=strlen($searchstring);
for ($i_s=0;$i_s<$searchlen;$i_s++){if
(substr($searchstring,$i_s,1)==$delimiter){$positions[]=$i_s; } }
}
}
You can work with the positions-array, but remember to unset it before calling the function again,
otherwise you'll fill it more and more :-)
Counting of positions begins with 0. If the charakter you search for ist not to be found in your
searchstring, the function returns $search_found=0, otherwise $search_found will be 1.
If typing the function, be sure to have three "=" in asking whether the charakter was
found.
--
http://www.php.net/manual/en/ref.strings.php
http://master.php.net/manage/user-notes.php?action=edit+25179
http://master.php.net/manage/user-notes.php?action=delete+25179
http://master.php.net/manage/user-notes.php?action=reject+25179