reading the html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mlecho
Forum Commoner
Posts: 53
Joined: Wed Feb 02, 2005 9:59 am

reading the html

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mlecho
Forum Commoner
Posts: 53
Joined: Wed Feb 02, 2005 9:59 am

Post 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>")
?>
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

print_r($matches); should give you the clue what you now need to do.

What does print_r($matches) output?
Post Reply