Autor Zpráva
Cup
Profil
$vysledek = str_replace('<br />', '<br>', $vysledek); // sjednotime si odentrovani... 
        $pole=explode("<br>", $vysledek);//rozdělíme na řádky,
        $maz_br = 0;
         foreach ($pole as $cast) {  // PROJDU RADKY 
          if(strpos($cast,"<pre>")!==false){$maz_br = 1;} // kdyz bude na radku PRE tak zacnu mazat mezery  
          if(strpos($cast,"</pre>")!==false){$maz_br = 0; }  // kdyz tam bude ukonceni pre tak prestanu mazat mezery 
          if($maz_br == 1)$cast = str_replace('<br>', ' ', $cast);  // mazu mezery 
          }
        
        $vysledek = implode(" ",$pole);



je to kousíček kódu ale nefunguje mi to ... smažou se mi všechny mezery nebo žádné nevidíte tam nějakej kiks?
Cup
Profil
v podstatě mi jde o toto

vstupní řetězec
Lorem Ipsum is<br />
simply dummy text of the printing<br />
<pre> and typesetting industry. Lorem I<br />
psum has been the industry's standard<br />
dummy text ever since the 1500s, when <br />
an unknown printer took a galley of type <br />
</pre>and scrambled it to make a type<br />
specimen book. It has survived not o<br />
nly five centuries, but also the leap into<br />
electronic typesetting, remaining essentia<br />


výstupní řetězec

Lorem Ipsum is<br />
simply dummy text of the printing<br />
<pre> and typesetting industry. Lorem I
psum has been the industry's standard
dummy text ever since the 1500s, when
an unknown printer took a galley of type
</pre>and scrambled it to make a type<br />
specimen book. It has survived not o<br />
nly five centuries, but also the leap into<br />
electronic typesetting, remaining essentia<br />


// odřádkování mezi značkami pre ve výstupním řetězci chybí

Nevíte prosím někdo jak ten kousek kódu poladit aby mě to jelo?
DJ Miky
Profil
Smysl toho skriptu má být odstranění všech <br> mezi <pre> a </pre>?

Pak by to šlo vyřešit regulárními výrazy:
$vysledek = preg_replace('@(<pre>)(.+)(</pre>)@uies', "'\\1'.str_replace(array('<br>','<br />'),'','\\2').'\\3'", $vysledek);
SwimX
Profil
DJ Miky
kódy v <pre> se zobraí tak jak jsou napsány v kódu, takže bych tvůj regulár s dovolením upravil:
$vysledek = preg_replace('@(<pre>)(.+)(</pre>)@uies', "'\\1'.str_replace(array('<br>','<br />'),'\r\n','\\2').'\\3'", $vysledek);
Cup
Profil
DJ Miky,SwimX,
pánové díky za pomoc původně jsem to chtěl taky řešit regulerním výrazem ale zjistil sem že na to nemam tak sem to chtěl obejít... díky
Cup
Profil
problem, regulerni vyraz odstranil <br /> ale nahradil to nepsanymi mezerami ... coz je ve vysledku toto

vstupní řetězec
Lorem Ipsum is<br />
simply dummy text of the printing<br />
<pre> and typesetting industry. Lorem I<br />
psum has been the industry's standard<br />
dummy text ever since the 1500s, when <br />
an unknown printer took a galley of type <br />
</pre>and scrambled it to make a type<br />
specimen book. It has survived not o<br />
nly five centuries, but also the leap into<br />
electronic typesetting, remaining essentia<br />


výstupní řetězec

Lorem Ipsum is<br />
simply dummy text of the printing<br />
<pre> and typesetting industry. Lorem I

psum has been the industry's standard

dummy text ever since the 1500s, when

an unknown printer took a galley of type

</pre>and scrambled it to make a type<br />
specimen book. It has survived not o<br />
nly five centuries, but also the leap into<br />
electronic typesetting, remaining essentia<br />


nevidíte tam ještě někde chybku? ... díky
Cup
Profil
pohoda ... vyresil jsem to ... .) ale bez vas ani ránu .. díky ...

$vysledek = preg_replace('@(<pre>)(.+)(</pre>)@uies', "'\\1'.str_replace(array('<br>','<br />'),' ','\\2').'\\3'", $vysledek);


mezera u str_replace
DJ Miky
Profil
SwimX
kódy v <pre> se zobraí tak jak jsou napsány v kódu

Právě proto... Je tam <br> i \n, takže odstraněním <br> ti tam pořád zbyde odřádkování (což pak ve výsledku nic nevyřeší, viz #6)

Cup
Ta mezera tam ani být nemusí, stačí to, co jsem poslal já (bez mezery) a ne SwimX.

Vaše odpověď


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0