regex vraag

Gestart doorRogier6 reacties58 weergaven

7 berichten · pagina 1 van 1

Rogier

Lid · Topicstarter

Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hey,

Ik heb met curl een scriptje geschreven die ervoor zorgt dat ik ergens een ding kan invullen.

Nu krijg ik dit als resultaat: (dit is de letterlijke code, ook de " " bij de eerste TD.)

<TR BGCOLOR=#E5F0E7>
    <TD class="resultData" >
        6547457546754764567457            
    </TD>
    <TD class="resultData">
        reyty rtyrety
    </TD>
    <TD class="resultData">
        8ewy
    </TD>
    <TD class="resultData">
                                    
    </TD>
    <TD class="resultData">
        ryteyretyerty
    </TD>
    <TD class="resultData">
        ryteryteryt
    </TD>
    <TD class="resultData">
        rtyertyerty
    </TD>
    <TD class="resultData">
        wtretewrtewr
    </TD>
    <TD class="resultData">
        blalwerwr
    </TD>    
    <TD class="resultData">
        bla
    </TD>
</TR>


Weet iemand hoe ik hiervan een array kan maken?

Ik heb geprobeerd:

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] retrieveValidData[COLOR= #007700]([/COLOR][COLOR= #0000BB]$bestand[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/preg_match_all"]preg_match_all[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"/<TD class="resultData">(.*?)</TD>/"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$bestand[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$resultaten[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$resultaten[/COLOR][COLOR= #007700];
}[/COLOR]
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Wat returned de functie nu voor waarde?
0
Berichten
308
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Via het DOMDocument(), kan je html inlezen zoals je het DOM gebruikt in JS.

Vb.

[COLOR= #0000BB]<?php
    $ret[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
        
    [COLOR= #0000BB]$DOM[/COLOR] [COLOR= #007700]= new[/COLOR] DOMDocument[COLOR= #007700]([/COLOR][COLOR= #DD0000]1.0[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]utf-8[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$html[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Dit bevat de html van je cURL request.[/COLOR]
    [COLOR= #0000BB]$DOM[/COLOR][COLOR= #007700]->[/COLOR]load[COLOR= #007700]([/COLOR][COLOR= #0000BB]$html[/COLOR][COLOR= #007700]);[/COLOR]
        
    [COLOR= #0000BB]$results[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$DOM[/COLOR][COLOR= #007700]->[/COLOR]getElementsByTagName[COLOR= #007700]([/COLOR][COLOR= #DD0000]TD[/COLOR][COLOR= #007700]);[/COLOR]
        
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$results[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]) {[/COLOR]
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]getAttribute[COLOR= #007700]([/COLOR][COLOR= #DD0000]class[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #DD0000]resultData[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$ret[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]nodeValue[COLOR= #007700];
        }
    }[/COLOR]
        
    [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$ret[/COLOR][COLOR= #007700];[/COLOR]
?>


Of iets dergelijks, t is al n tijdje geleden dat ik nog met HTML, XML heb gewerkt in php
0
Rogier

Lid · Topicstarter

Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aarclay schreef:
Wat returned de functie nu voor waarde?
witte pagina
Robbeing schreef:
Via het DOMDocument(), kan je html inlezen zoals je het DOM gebruikt in JS.

Vb.
[COLOR= #0000BB]<?php
    $ret[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
        
    [COLOR= #0000BB]$DOM[/COLOR] [COLOR= #007700]= new[/COLOR] DOMDocument[COLOR= #007700]([/COLOR][COLOR= #DD0000]1.0[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]utf-8[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$html[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Dit bevat de html van je cURL request.[/COLOR]
    [COLOR= #0000BB]$DOM[/COLOR][COLOR= #007700]->[/COLOR]load[COLOR= #007700]([/COLOR][COLOR= #0000BB]$html[/COLOR][COLOR= #007700]);[/COLOR]
        
    [COLOR= #0000BB]$results[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$DOM[/COLOR][COLOR= #007700]->[/COLOR]getElementsByTagName[COLOR= #007700]([/COLOR][COLOR= #DD0000]TD[/COLOR][COLOR= #007700]);[/COLOR]
        
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$results[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]) {[/COLOR]
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]getAttribute[COLOR= #007700]([/COLOR][COLOR= #DD0000]class[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #DD0000]resultData[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$ret[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]nodeValue[COLOR= #007700];
        }
    }[/COLOR]
        
    [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$ret[/COLOR][COLOR= #007700];[/COLOR]
?>


Of iets dergelijks, t is al n tijdje geleden dat ik nog met HTML, XML heb gewerkt in php

Krijg dat helaas ook niet werkend sadley
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Die DOM is wel een hele goede manier... Wat lukt daar niet mee, wat heb je al geprobeerd?
Met iets als: Werkt niet kunnen we niks.
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$string[/COLOR] [COLOR= #007700]=[/COLOR] deinputhier[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$string[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"<TR BGCOLOR=#E5F0E7>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$string[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"</TR>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$string[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"</TD>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$string[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"<TD class="resultData" >"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"<TD class="resultData">"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700]);[/COLOR]
?>


Dit is waarschijnlijk niet de beste manier, maar werkt wel
0
Rogier

Lid · Topicstarter

Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
@Aarclay: ik bied anders ook wel meer dan "werkt niet". Als ik gebruik maak van de DomDocument class (en ja ik heb php.net geraadpleegd) krijg ik net als met preg_match en witte pagina. (ik heb dan vrijwel dezelfde als Robbeing voor me gemaakt had, met een paar probeersels zegmaar). Dat bedoel ik met "kreeg het niet werkend".

@Eleky: Dat had ik nog niet bedacht. Is zeker een slimme oplossing, ik wil alleen kijken of het met dat DomDocument kan en of iemand een fundamentele fout bij Robbeing eruit kan halen, want alle kleine dingetjes heb ik al geprobeerd. In ieder heel erg bedankt voor je input!
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren