Jump to content

Add to array


Scummy12

Recommended Posts

I would write a little function that you can reuse.

<?php
/*
function to match all from given start & end point
return results as array
*/
function parseArray($string, $openTag, $closeTag, $excluding = false) {
preg_match_all("($openTag(.*)$closeTag)siU", $string, $matches);
if($excluding) {
  return $matches[1];
}
return $matches[0];
}


/*
usage
*/
$string  = "<id>18800<end><id>18436<end>";
$results = parseArray($string, "<id>", "<end>", true);
print "<pre>";
print_r($results);
print "</pre>";
?>

Link to comment
https://forums.phpfreaks.com/topic/212338-add-to-array/#findComment-1106386
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.