Search code examples
phpdrupaldrupal-7

How to use preg_match_all in Drupal


I am currently in the process of developing a site for a football club. I pick a ranking that is on an official website (I have permission). The problem is that there is no RSS feed, then I have to tinker. I create a php file with this code:

    <?php

$adresse = "http://lafa.fff.fr/competitions/php/club/club_classement_deta.php?sa_no=2011&cp_no=272284&ph_no=1&gp_no=1&cl_no=3232&eq_no=1";
$page = file_get_contents ($adresse);

preg_match_all ('#<table cellpadding="0" cellspacing="0" border="0" summary="" class="tablo bordure ac">(.*?)</table>#', $page, $prix);
// On stocke dans le tableau $prix les éléments trouvés

echo '<table>';

for($i = 0; $i < count($prix[1]); $i++) // On parcourt le tableau $prix[1]
{

    echo $prix[1][$i]; // On affiche le prix

}

echo '</table>';


?>

The problem is that I have that to integrate drupal and it does not works. I tried to create a module and create a function, same result. I create a content page with php code, same result, it does not work.

How can I do that ?

Cheers

Update : In my drupal module.module:

    <?php

    include_once('simple_html_dom.php');

    function classements_liste(){   

        $url="http://lafa.fff.fr/competitions/php/club/club_classement_deta.php?sa_no=2011&cp_no=272284&ph_no=1&gp_no=1&cl_no=3232&eq_no=1";
        $dom = str_get_html(file_get_contents($url));

        $tables = $dom->find('table');
        echo $tables[0];
        echo $tables[1];



    }

    function classements_menu() {

        $items['classements/list'] = array(
        'title' => 'Liste des classements',
        'page callback' => 'classements_liste',
        'page arguments' => array('access content'),
        'access callback' => true,
        'type' => MENU_CALLBACK,
        );

        return $items;


    }


?>  

Result:

enter image description here


Solution

  • Use concatenation as i define below :

    $adresse = "http://lafa.fff.fr/competitions/php/club/club_classement_deta.php?sa_no=2011&cp_no=272284&ph_no=1&gp_no=1&cl_no=3232&eq_no=1";
            $page = file_get_contents ($adresse);
            preg_match_all('#<table cellpadding="0" cellspacing="0" border="0" summary="" class="tablo bordure ac">(.*?)</table>#', $page, $prix);
            $data   =   '<table>'; // here the table is define
            for($i = 0; $i < count($prix[1]); $i++){
                $data   .='<tr><td>'.$prix[1][$i].'</td></tr>'; // add table row
            }
            $data   .=   '</table>'; // finish table
          $block['content'] = $data; // assign to block or simple print in case of page