note 40066 modified in function.strpos by aidan

From: Date: Thu, 10 Jun 2004 06:57:49 +0000
Subject: note 40066 modified in function.strpos by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-70812@lists.php.net to get a copy of this message
I wanted to write a parser that gets the value of searchme[15] and also the value of searchmealso(166). it can be modified to return the amount of found strings or something else...i hope you find it useful, even if the function returns nothing at the moment. <?php $text="i wanted to write a parser that gets the value of searchme[15] and also the value of searchmealso(166). it can be modified to return the amount of found strings or something else...i hope you find it useful, even if the function returns nothing at the moment. "; testreport($text); function testreport($text) { for($i=0;$i<strlen($text);$i++) { $s=1; $maxsize=5; $searchedfor[1]="searchme"; $searchedfor[2]="searchmealso"; $index_on_for[1]="["; $index_on_for[2]="("; $index_off_for[1]="]"; $index_off_for[2]=")"; while($searchedfor[$s]!="") { $word=""; $size=strlen($searchedfor[$s]); for($i_up=$i;$i_up<$i+$size;$i_up++) { $word.=$text{$i_up}; } if($word==$searchedfor[$s]) { echo "Jeehaaw! Found a $word!<br />"; $v_up=$i_up; $index_found="false"; $value=""; while($index_found=="false") { if($text{$v_up}==$index_on_for[$s])$v_up++; if($text{$v_up}!=$index_off_for[$s])$value.=$text{$v_up}; if($text{$v_up}==$index_off_for[$s] || $v_up>$i_up+$maxsize)$index_found="true"; $v_up++; } echo "Value of $word: $value!<br />"; } $s++; } } } ?> --was-- <?php $text="i wanted to write a parser that gets the value of searchme[15] and also the value of searchmealso(166). it can be modified to return the amount of found strings or something else...i hope you find it useful, even if the function returns nothing at the moment. "; testreport($text); function testreport($text) { for($i=0;$i<strlen($text);$i++) { $s=1; $maxsize=5; $searchedfor[1]="searchme"; $searchedfor[2]="searchmealso"; $index_on_for[1]="["; $index_on_for[2]="("; $index_off_for[1]="]"; $index_off_for[2]=")"; while($searchedfor[$s]!="") { $word=""; $size=strlen($searchedfor[$s]); for($i_up=$i;$i_up<$i+$size;$i_up++) { $word.=$text{$i_up}; } if($word==$searchedfor[$s]) { echo "Jeehaaw! Found a $word!<br />"; $v_up=$i_up; $index_found="false"; $value=""; while($index_found=="false") { if($text{$v_up}==$index_on_for[$s])$v_up++; if($text{$v_up}!=$index_off_for[$s])$value.=$text{$v_up}; if($text{$v_up}==$index_off_for[$s] || $v_up>$i_up+$maxsize)$index_found="true"; $v_up++; } echo "Value of $word: $value!<br />"; } $s++; } } } ?> http://www.php.net/manual/en/function.strpos.php

« previous php.notes (#70812) next »