Autor Zpráva
UrbiCZ
Profil
Zdravim. Pokouším se rozparsovat tento chunk:

</table>
<p><b>Pamela Denise Anderson</b> (born 1 July 1967)<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span>[</span>2<span>]</span></a></sup><sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span>[</span>3<span>]</span></a></sup><sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span>[</span>4<span>]</span></a></sup><sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span>[</span>5<span>]</span></a></sup> is a Canadian-American actress, <a href="/wiki/Model_(person)" title="Model (person)" class="mw-redirect">model</a>, <a href="/wiki/Television_producer" title="Television producer">producer</a>, author, activist, and former <a href="/wiki/Showgirl" title="Showgirl">showgirl</a>, known for her roles on the television series <i><a href="/wiki/Home_Improvement_(TV_series)" title="Home Improvement (TV series)">Home Improvement</a></i>, <i><a href="/wiki/Baywatch" title="Baywatch">Baywatch</a></i>, and <i><a href="/wiki/V.I.P._(TV_series)" title="V.I.P. (TV series)">V.I.P.</a></i> She was chosen as a <a href="/wiki/Playboy_Playmate" title="Playboy Playmate">Playmate of the Month</a> for <i><a href="/wiki/Playboy" title="Playboy">Playboy</a></i> magazine in February 1990.<sup id="cite_ref-playmate_6-0" class="reference"><a href="#cite_note-playmate-6"><span>[</span>6<span>]</span></a></sup> For a time, she was known as <b>Pamela Anderson Lee</b> (or <b>Pamela Lee</b>) after marrying <a href="/wiki/M%C3%B6tley_Cr%C3%BCe" title="Mötley Crüe">Mötley Crüe</a> drummer <a href="/wiki/Tommy_Lee" title="Tommy Lee">Tommy Lee</a>. She maintains dual <a href="/wiki/Canadian_nationality_law" title="Canadian nationality law">Canadian</a> and <a href="/wiki/American_nationality_law" title="American nationality law" class="mw-redirect">American</a> citizenship.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span>[</span>7<span>]</span></a></sup> Anderson is a notable member of the <a href="/wiki/Animal_Rights" title="Animal Rights" class="mw-redirect">Animal Rights</a> movement and has conducted campaigns condemning the commercial fur industry and promoting veganism<sup id="cite_ref-PETA_CrueltyDoesntFly_8-0" class="reference"><a href="#cite_note-PETA_CrueltyDoesntFly-8"><span>[</span>8<span>]</span></a></sup> through the animal welfarist organisation <a href="/wiki/PETA" title="PETA" class="mw-redirect">PETA</a>.</p>
<p></p>
<div id="toc" class="toc">

Snažím se vyhledat text mezi tagem </table> a <div id="toc" class="toc"> a to takto:

$najit = preg_match_all('/<\/table>(.)+<div id="toc" class="toc">/',$wiki, $vlajky_nasich_otcu);

Bohužel mi to stále nefunguje a nemůžu přijít na to, kde je problém. Zkoušel jsem si testovací řetězec vytvořit na lokále a vše funguje. Když ovšem sosnu tento řetězec z netu, tak výraz nefunguje. Díky za radu.
Joker
Profil
UrbiCZ:
Nešlo by to zpracovat normálně HTML parserem?
UrbiCZ
Profil
Učím se regulární výrazy a tak to chci zavdat takto...
DJ Miky
Profil
Problém bude nejspíš v tom, že tečka standardně nechytá znaky nového řádku. Vzhledem k tomu, že v ukázce je hledaný blok rozdělený do více řádků, je potřeba toto chování změnit modifikátorem s:
/<\/table>(.)+<div id="toc" class="toc">/s
lionel messi
Profil
Odporúčam riešenie od DJ Miky, pred niekoľkými mesiacmi som sa trápil s tým, ako odstrániť doctype a hlavičku stránky pomocou RV, všetko fungovalo, ale konce riadkov sa nejak nechytali, vzdal som to a až neskôr náhodou som prišiel na modifikátor s, ktorý toto správanie odstránil.
UrbiCZ
Profil
Super, to bude nejspíš ono. Jenže teď se nepovede ani parsování, protože server nechce odeslat data. Zobrazí se v Googlu kód chyby: ERR_EMPTY_RESPONSE.

Kód:

$wiki = file_get_contents("http://en.wikipedia.org/wiki/Pamela_Anderson");

$najit = preg_match_all('/<\/table>(.)+<div id="toc" class="toc">/s',$wiki, $output);


V logu chyb se zobrazí tohle:
[Tue Feb 04 12:09:59 2014] [notice] Parent: child process exited with status 255 -- Restarting.
[Tue Feb 04 12:09:59 2014] [notice] Apache/2.2.22 (Win32) PHP/5.4.5 configured -- resuming normal operations
[Tue Feb 04 12:09:59 2014] [notice] Server built: Jan 28 2012 11:16:39
[Tue Feb 04 12:09:59 2014] [notice] Parent: Created child process 7572
[Tue Feb 04 12:09:59 2014] [notice] Child 7572: Child process is running
[Tue Feb 04 12:09:59 2014] [notice] Child 7572: Acquired the start mutex.
[Tue Feb 04 12:09:59 2014] [notice] Child 7572: Starting 50 worker threads.
[Tue Feb 04 12:09:59 2014] [notice] Child 7572: Starting thread to listen on port 80.
DarkMeni
Profil
Asi nedostal žádnej výstup (kromě http hlaviček), tak proto ta chyba
Zkus to třeba s var_dump(), ten pokaždý něco vypíše, minimálně aspoň že "NULL"

<?php
$najit = preg_match_all('/<\/table>(.+)<div id="toc" class="toc">/s',$wiki, $output);
var_dump($output);
?>

A možná bude stačit preg_match() - to, co hledáš je tam jen jednou, ne?
UrbiCZ
Profil
Zkoušel jsem to s výstupem pomocí print_r i var_dump, ale nic.

jojo, preg_match postačí....
UrbiCZ
Profil
Tak vyřešeno, stačilo odstranit závorku ve které byla tečka:
$najit = preg_match_all('/<\/table>.+<div id="toc" class="toc">/s', $wiki, $matches);

Díky.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

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

0