Question

$match_expression = '/<a href="look.php\?id=(.*)" title="Look page: (.*)">(.*)<\/A>/';
  $radompgr =  preg_match_all($match_expression,$q2,$match, PREG_SET_ORDER);
  if($radompgr == TRUE){echo "found $radompgr<br>";}else{echo "not found $radompgr<br>";} //found
for ($i = 0; $i < count($match); $i++) {
  $mathcas = $match[$i][1];
   $radom = preg_match('/[0-9a-z]{39,41}/',$mathcas,$matches2); 
   if($radom == TRUE){
   $match11 = $matches2[1];
   echo "found".$i.": ".$match11."";}else{echo"".$i."not found :(<br>";}
} //  "found0", but don`t show $match11 variable.

"Afficher found0", mais don `t montrer match11 $. Comment faire match $ 11 à montrer? Retour:

  

Indication: Undefined offset: 1 in C: \ xampp \ htdocs \ page.php sur la ligne 75   found0:   Indication: Undefined offset: 1 in C: \ xampp \ htdocs \ copie \ page.php sur la ligne 75   found1:   Indication: Undefined offset: 1 in C: \ xampp \ htdocs \ copie \ page.php sur la ligne 75   found2:

Désolé si mon anglais est pas parfait, je ne suis pas originaire. :) Merci de votre aide.

Était-ce utile?

La solution

Vous avez oublié de joindre le () dans preg_match ():

$match_expression = '/<a href="look.php\?id=(.*)" title="Look page: (.*)">(.*)<\/A>/';
$radompgr = preg_match_all($match_expression, $q2, $match, PREG_SET_ORDER);

if ($radompgr >= 1)
{
    echo 'found ' . $radompgr;

    for ($i = 0; $i < count($match); $i++)
    {
        $mathcas = $match[$i][1];

        $radom = preg_match('/([0-9a-z]{39,41})/', $mathcas, $matches2);

        if ($radom >= 1)
        {
            $na = $matches2[1];

            echo 'found' . $i . ': ' . $na;
        }

        else
        {
            echo $i . 'not found';
        }
    }
}

else
{
    echo 'not found ' . $radompgr;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top