Page 1 of 1

reading the html

Posted: Tue Aug 08, 2006 6:15 am
by mlecho
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi all...i am trying to have php read html files. i have a bunch that all have the same format (essentially) and i would like to extract the text between tags: ie- [b]<br><b> [/b]sample text [b]<b>[/b] // output would be [i]sample text[/i]

i confess i am getting very lost here, and i sincerely hope i am heading the right direction with this. I am piecing this together, via the php manual...so you can see how unexperienced i am with php!

Code: Select all

<?php
$menuType=$_GET['gallery'];
$directory="images/$menuType/".$menuType.".html";
$fileName="images/".$menuType."/".$menuType.".html";
$handle=fopen($fileName,"r");
$contents=fread($handle,filesize($fileName));
$words=".+";//this is where i am getting lost
$wanted=preg_match_all('/\<br\>\<b\>$words/i', $contents, $matches);//this is where i am completely lost

foreach ($matches as $val) {
    echo $val;//states Array, so i must be close???
}
fclose($handle);
?>
thanks for your help, and please no un-inspirational comments on my lack of proper php code.


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Aug 08, 2006 9:04 am
by feyd

Posted: Tue Aug 08, 2006 11:01 am
by mlecho
thanks feyd....i was not fair, as i did not say what i am doing with the values....after i get these values, i need to have them produced in a simple xml format...i am getting closer. The foreach statement still wants to just write Array.

Code: Select all

<?php
//$menuType=$_GET['gallery'];
$menuType="test";
$directory="images/$menuType/".$menuType.".html";
$fileName="images/".$menuType."/".$menuType.".html";
$handle=fopen($fileName,"r");
$contents=fread($handle,filesize($fileName));
$wanted=preg_match_all('/<b>(.*)<\/b>/i', $contents, $matches);

fclose($handle);

//echo ("<xml>");
foreach($matches as $val){
echo ("<caption>".$val."</caption>");
}
//echo("</xml>")
?>

Posted: Tue Aug 08, 2006 11:23 am
by JayBird
print_r($matches); should give you the clue what you now need to do.

What does print_r($matches) output?