note 72612 added to function.strpos

From: Date: Fri, 26 Jan 2007 07:23:46 +0000
Subject: note 72612 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-122213@lists.php.net to get a copy of this message
Get text between $s1 and $s2, return an array contains every occurrence (based on code of old comment/s but with offset and without strtolower) Sample: $myDivsContent = getStrsBetween("<div","</div>",$myHtmlSrc); Sample: or...get rows for html table ... ... //using TextBetween from old comment... $aTable = TextBetween("<table","</table>",$myHtmlSrc); $rows = getStrsBetween("<tr","</tr>",$aTable); ... ... function getStrsBetween($s1,$s2,$s,$offset=0){ $result = array(); $index= 0; $L1 = strlen($s1); $found = false; do{ if($L1>0){ $pos1 = strpos($s,$s1,$offset); } else { $pos1=$offset; } if($pos1 !== false){ if($s2 == '') $result[$index++]= substr($s,$pos1+$L1); $pos2 = strpos(substr($s,$pos1+$L1),$s2,$L1); if($pos2!==false){ $result[$index++]= substr($s,$pos1+$L1,$pos2); $offset += $pos2 + strlen($s2); } else{ $pos1 = false; } } }while($pos1 !== false); return $result; } BUGs/Problems: Function do not stop while $s1 is found in $s. ---- Server IP: 129.16.214.50 Probable Submitter: 83.181.210.72 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/72612 Del: integrated -- https://master.php.net/note/delete/72612/integrated Del: useless -- https://master.php.net/note/delete/72612/useless Del: bad code -- https://master.php.net/note/delete/72612/bad+code Del: spam -- https://master.php.net/note/delete/72612/spam Del: non-english -- https://master.php.net/note/delete/72612/non-english Del: in docs -- https://master.php.net/note/delete/72612/in+docs Del: other reasons-- https://master.php.net/note/delete/72612 Reject -- https://master.php.net/note/reject/72612 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122213) next »