note 66005 added to function.ereg
| From: | \ | Date: | Thu, 11 May 2006 20:16:38 +0000 |
| Subject: | note 66005 added to function.ereg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111152@lists.php.net to get a copy of this message | ||
Try this version instead of the one previously posted.
<?php
/**
Returns an array containing each of the sub-strings from text that
are between openingMarker and closingMarker. The text from
openingMarker and closingMarker are not included in the result.
This function does not support nesting of markers.
*/
function returnSubstrings($text, $openingMarker, $closingMarker) {
$openingMarkerLength = strlen($openingMarker);
$closingMarkerLength = strlen($closingMarker);
$result = array();
$position = 0;
while (($position = strpos($text, $openingMarker, $position)) !== false) {
$position += $openingMarkerLength;
if (($closingMarkerPosition = strpos($text, $closingMarker, $position)) !== false) {
$result[] = substr($text, $position, $closingMarkerPosition - $position);
$position = $closingMarkerPosition + $closingMarkerLength;
}
}
return $result;
}
// Example:
$exampleText = "<b>bonjour</b> Ã tous, <b>comment</b> allez-vous
?";
$result = returnSubstrings($exampleText, "<b>", "</b>");
var_export($result);
// Prints:
// array (
// 0 => 'bonjour',
// 1 => 'comment',
// )
?>
----
Server IP: 216.235.15.211
Probable Submitter: 207.194.109.185
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.ereg.php
Edit -- http://master.php.net/note/edit/66005
Del: integrated -- http://master.php.net/note/delete/66005/integrated
Del: useless -- http://master.php.net/note/delete/66005/useless
Del: bad code -- http://master.php.net/note/delete/66005/bad+code
Del: spam -- http://master.php.net/note/delete/66005/spam
Del: non-english -- http://master.php.net/note/delete/66005/non-english
Del: in docs -- http://master.php.net/note/delete/66005/in+docs
Del: other reasons-- http://master.php.net/note/delete/66005
Reject -- http://master.php.net/note/reject/66005
Search -- http://master.php.net/manage/user-notes.php