fer0an Posted January 23, 2010 Share Posted January 23, 2010 hello I want select text between some html code and then replace it by ''.( replace from 'href' until '">' then replace this text with '') this is my code : <?php set_time_limit(0) ; ob_implicit_flush(true); ob_end_flush(); function TextBetween($s1,$s2,$s){ $s1 = strtolower($s1); $s2 = strtolower($s2); $L1 = strlen($s1); $scheck = strtolower($s); if($L1>0){$pos1 = strpos($scheck,$s1);} else {$pos1=0;} if($pos1 !== false){ if($s2 == '') return substr($s,$pos1+$L1); $pos2 = strpos(substr($scheck,$pos1+$L1),$s2); if($pos2!==false) return substr($s,$pos1+$L1,$pos2); } return ''; } $title = 'Jornal O Estado de SP em href="http://domain.com/tag/pdf/" class="st_tag internal_tag" rel="tag" title="Posts tagged with pdf">PDF, Sábado, 23 de href="http://domain.com/tag/janeiro/" class="st_tag internal_tag" rel="tag" title="Posts tagged with janeiro">Janeiro de 2010 href="http://domain.com/tag/pdf/" class="st_tag internal_tag" rel="tag" title="Posts tagged with pdf">PDF | href="http://domain.com/tag/brazil/" class="st_tag internal_tag" rel="tag" title="Posts tagged with brazil">Brazil | 84 href="http://domain.com/tag/pages/" class="st_tag internal_tag" rel="tag" title="Posts tagged with pages">Pages | 32 MB'; $title3 = textbetween('href="','">',$title); while ($title3 != "") { $title2 = str_ireplace ($title3,'',$title); echo $title2."<br>" ; } echo $title2."<br>" ; ?> anyone can help me? Quote Link to comment https://forums.phpfreaks.com/topic/189533-select-text-between-and-replace-with/ Share on other sites More sharing options...
jskywalker Posted January 23, 2010 Share Posted January 23, 2010 with what do you need help..... while ($title3 != "") { $title2 = str_ireplace ($title3,'',$title); echo $title2."<br>" ; } where does $title3 change value ??? Quote Link to comment https://forums.phpfreaks.com/topic/189533-select-text-between-and-replace-with/#findComment-1000437 Share on other sites More sharing options...
fer0an Posted January 23, 2010 Author Share Posted January 23, 2010 hi $title3 = textbetween('href="','">',$title) so until it's have some char $title2 = str_ireplace ($title3,'',$title); so replace html codes with nothing. the problem is after run codes only first textbetween replace and for another nothing happen. I want after run this codes all of textbetween replace with nothing. thank you Quote Link to comment https://forums.phpfreaks.com/topic/189533-select-text-between-and-replace-with/#findComment-1000543 Share on other sites More sharing options...
jskywalker Posted January 23, 2010 Share Posted January 23, 2010 i have 2 options 1) you need to read http://php.net/manual/en/control-structures.while.php and lear all about how to use 'while' in PHP 2) i'm out of options or did i miss something? Quote Link to comment https://forums.phpfreaks.com/topic/189533-select-text-between-and-replace-with/#findComment-1000554 Share on other sites More sharing options...
laffin Posted January 23, 2010 Share Posted January 23, 2010 $title=preg_replace('/href=".*?"/','',$title); Quote Link to comment https://forums.phpfreaks.com/topic/189533-select-text-between-and-replace-with/#findComment-1000592 Share on other sites More sharing options...
fer0an Posted January 24, 2010 Author Share Posted January 24, 2010 thank you but I recive an error : Warning: Wrong parameter count for preg_replace() in /home/... Quote Link to comment https://forums.phpfreaks.com/topic/189533-select-text-between-and-replace-with/#findComment-1000709 Share on other sites More sharing options...
laffin Posted January 24, 2010 Share Posted January 24, 2010 I tried that, with this simple script: <?php $title = 'Jornal O Estado de SP em href="http://domain.com/tag/pdf/" class="st_tag internal_tag" rel="tag" title="Posts tagged with pdf">PDF, Sábado, 23 de href="http://domain.com/tag/janeiro/" class="st_tag internal_tag" rel="tag" title="Posts tagged with janeiro">Janeiro de 2010 href="http://domain.com/tag/pdf/" class="st_tag internal_tag" rel="tag" title="Posts tagged with pdf">PDF | href="http://domain.com/tag/brazil/" class="st_tag internal_tag" rel="tag" title="Posts tagged with brazil">Brazil | 84 href="http://domain.com/tag/pages/" class="st_tag internal_tag" rel="tag" title="Posts tagged with pages">Pages | 32 MB'; echo $title=preg_replace('/href=".*?"/','',$title); ?> And it worked as expected Quote Link to comment https://forums.phpfreaks.com/topic/189533-select-text-between-and-replace-with/#findComment-1000712 Share on other sites More sharing options...
fer0an Posted January 24, 2010 Author Share Posted January 24, 2010 solved thank you laffin Quote Link to comment https://forums.phpfreaks.com/topic/189533-select-text-between-and-replace-with/#findComment-1000713 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.