Jump to content

Recommended Posts

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&#225;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? :cry:

Link to comment
https://forums.phpfreaks.com/topic/189533-select-text-between-and-replace-with/
Share on other sites

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.