note 25179 modified in ref.strings by maxim

From: Date: Tue, 12 Nov 2002 16:25:47 +0000
Subject: note 25179 modified in ref.strings by maxim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-39400@lists.php.net to get a copy of this message
I've written a small function, which extracts all positions of a given character 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. --was-- 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

« previous php.notes (#39400) next »