Originariamente inviato da micdas
ciao LuigiMem

e grazie per la risposta.
Replico con altre parole il mio intento......forse non sono stato abbastanza chiaro.
Ho un file (menù.php che mi stampa dei link comprensivi di query-string strutturato in questa maniera
Riporto il file integrale
Codice PHP:
<ul class="menuNav">[*]<h3>contenuti PHP</h3>
<?php
$choice = $_REQUEST['choice'];
echo "[*]<a" . (($choice == "introduzione") ? " class='currentN'" : "") . " href=\"introduzione.php?settore=lab_php&choice=introduzione\">Introduzione</a>\n";
echo "[*]<a" . (($choice == "el_funz") ? " class='currentN'" : "") . " href=\"el_funz.php?settore=lab_php&choice=el_funz\">Elenco risorse</a>\n";
echo "[*]<a" . (($choice == "funzioni_pers") ? " class='currentN'" : "") . " href=\"funzioni_pers.php?settore=lab_php&choice=funzioni_pers&pref=fun\">Funzioni</a>\n";
echo "[*]<a" . (($choice == "stringhe") ? " class='currentN'" : "") . " href=\"stringhe.php?settore=lab_php&choice=stringhe&pref=str\">stringhe</a>\n";
echo "[*]<a" . (($choice == "numeri") ? " class='currentN'" : "") . " href=\"numeri.php?settore=lab_php&choice=numeri&pref=num\">numeri</a>\n";
echo "[*]<a" . (($choice == "cicli") ? " class='currentN'" : "") . " href=\"cicli.php?settore=lab_php&choice=cicli&pref=cic\">Strutture controllo - cicli</a>\n";
echo "[*]<a" . (($choice == "matrici_array") ? " class='currentN'" : "") . " href=\"matrici_array.php?settore=lab_php&choice=matrici_array&pref=arr\">Array o Matrici</a>\n";
echo "[*]<a" . (($choice == "gestione_files") ? " class='currentN'" : "") . " href=\"gest_files.php?settore=lab_php&choice=gestione_files&pref=fil\">gestione files</a>\n";
echo "[*]<a" . (($choice == "gest_data") ? " class='currentN'" : "") . " href=\"gest_data.php?settore=lab_php&choice=gest_data&pref=dat\">gestione date orari</a>\n";
echo "[*]<a" . (($choice == "link") ? " class='currentN'" : "") . " href=\"link.php?settore=lab_php&choice=link&pref=lin\">link</a>\n";
echo "[*]<a" . (($choice == "php_to_pdf") ? " class='currentN'" : "") . " href=\"create_pdf_to_php.php?settore=lab_php&choice=php_to_pdf&pref=pdf\">da PHP a PDF</a>\n";
echo "[*]<a" . (($choice == "show_hide") ? " class='currentN'" : "") . " href=\"show_hide.php?settore=lab_php&choice=show_hide&pref=ide\">PHP-js Show/Hide</a>\n";
echo "[*]<a" . (($choice == "varie") ? " class='currentN'" : "") . " href=\"varie.php?settore=lab_php&choice=varie&pref=var\">Varie</a>\n";
?>[/list]
I files da leggere hanno tutti un prefisso di 3 lettere differente da ciascun argomento (quelli indicati nel menù).
In altro file, tra le varie righe lette nel file, debbo leggere il prefisso abbinato a ciascun link per ricavarne il relativo choise. Uso questo codice:
Codice PHP:
<?php
$lines = file("menu.php");
$elenco_files = glob('???_*.php');
$pattern_pref = "(pref=(.*?)> )";
$pattern_choise = "(choice=(.*?)> )";
for ($i = 0; $i < count ($elenco_files); $i++) {
$parts = explode('_', $elenco_files[$i], 2);
$pref_find = $parts[0];
echo $pref_find . "
\n";
$filename = $elenco_files[$i];
$current = file_get_contents($filename);
for($b=0; $b < count($lines); $b++) {
preg_match($pattern_pref, $lines[$b], $result_1);
$pref = $result_1[1];
if ($pref == $pref_find) {
preg_match($pattern_choise, $lines[$b], $result_2);
$choise = $result_2[1];
echo $pref_find . " - " . $pref . " - " . $choice . "
\n";
}
}
}
?>
In questo il $pref_find mi viene letto regolarmente, ma non mi viene restituito il $pref restituito da preg_match().
Io penso che siano errati sia il $pattern_pref che il $pattern_choise.