PHP 8.5.0 Alpha 2 available for testing

Voting

: min(four, four)?
(Example: nine)

The Note You're Voting On

usulaco at gmail dot com
14 years ago
Parse strings between two others in to array.

<?php
function g($string,$start,$end){
preg_match_all('/' . preg_quote($start, '/') . '(.*?)'. preg_quote($end, '/').'/i', $string, $m);
$out = array();

foreach(
$m[1] as $key => $value){
$type = explode('::',$value);
if(
sizeof($type)>1){
if(!
is_array($out[$type[0]]))
$out[$type[0]] = array();
$out[$type[0]][] = $type[1];
} else {
$out[] = $value;
}
}
return
$out;
}
print_r(g('Sample text, [/text to extract/] Rest of sample text [/WEB::http://google.com/] bla bla bla. ','[/','/]'));
?>

results:
Array
(
[0] => text to extract
[WEB] => Array
(
[0] => http://google.com
)

)

Can be helpfull to custom parsing :)

<< Back to user notes page

To Top