I'd like to make a function that returns content between tags (either the whole string or a specified number of letters after the opening tag) Linear code is below:
$tag='<body>';
//case1
$source=substr($source,strpos($source,$tag)+strlen($tag));
$sub=substr($source,0,strpos($source,'<'));
//case2
$source=substr($source,strpos($source,$tag)+strlen($tag));
$sub=substr($source,0,3);
The function will be accepting 3 parameters: the source code, the specified tag and the substring length (for case 2) and will return 2 variables: the trimmed source and the substring. So basicaly I want to have a function like this:
function p($source,$tag,$len) {
$source=substr($source,strpos($source,$tag)+strlen($tag));
if(isset($len)) $sub=substr($source,0,$len);
else $sub=substr($source,0,strpos($source,'<'));
$ret=array();
$ret[0]=$source;
$ret[1]=$sub;
return $ret;
}
//
$source=p($source,'<strong>')[0];
$sub1=p($source,'<strong>')[1];
$source=p($source,'<p>',100)[0];
$sub2=p($source,'<p>',100)[1];