Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2008
    Messaggi
    121

    [PHP] errore preg_match...

    Ciao, non mi ricordo bene come usare preg_match e mi da un errore, penso sia dato dagli \ e / sbagliati, mi sapete indicare come scrivere questo correttamente:

    Codice PHP:
    if (preg_match("/<h1>(.*?)</h1>/i"$page$match)) 
    ??

    Grazie... ciaoo

  2. #2
    prova:
    if (preg_match("/<h1>(.*?)<\/h1>/i, $page, $match)

  3. #3
    Come sopra.
    Poichè l'espressione regolare è delimitata da slash ( / ), devi escapare quel carattere affinchè venga interpretato per quel che è, infatti come vedi da </h1> è diventato <\/h1>.

    CIao
    "Il problema delle citazioni su Internet è verificarne l'autenticità." (Winston Churchill)

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2008
    Messaggi
    121
    vi posto tutto il codice:
    Codice PHP:
    $page '...<h1>




    title




    ...        <span class="date">(2008)</span>
    </h1>
    '
    ;

    if (
    preg_match("/<h1>(.*?)<\/h1>/i"$page$match)) {
        
    $t $match[1];
        echo 
    "trovato! $t";
    } else {
        echo 
    "Ricerca fallita!";

    Mi da sempre "Ricerca fallita!", mente l'output dovrebbe essere: "title...<span class="date">(2008)</span>"

    mi sapete aiutare?

  5. #5
    $page = '<h1>title<span class="date">(2008)</span></h1>';
    if(preg_match("/<h1[^>]*>(.*?)<\/h1>/", $page, $match)){
    var_dump($match);
    }

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.