PDA

View Full Version : Using PHP to read an HTML ID



God's Webmaster
02-07-2007, 09:53 AM
I would like to make a script that would allow my website visitors to email articles to a friend -- the article, not just a link.

In the past, I used Javascript to get an ID-tagged section of the article and print it, i.e.:
<div id="PrintReady">---ARTICLE---</div> Is there some way to do the same thing with PHP?

I used a Perl script in the past that read the webpage and emailed it. Problem is, it did not embed the CSS file or the pictures. Without the CSS, the page didn't look right. I would like to get just the article text so I can then format it in an email.

Thank you for the help!

Joel

aceofspades
02-07-2007, 09:56 AM
cant you just use an XML parser.

God's Webmaster
02-07-2007, 10:44 AM
cant you just use an XML parser.

Unfortunately, I'm unfamiliar with XML, and a beginner with PHP. How would I use an XML parser, and how would I then email the data? No, I'm not asking you to write a script for me.:D I just need some guidance as to where I should start and what I should do.

Joel

aceofspades
02-07-2007, 11:23 AM
Have you tried using HTMLSQL? It pretty easy. U just retrieve an XML document by doing SELECT * FROM a WHERE id=25. Or you can use a build in XML parser like SimpleXML.

God's Webmaster
02-07-2007, 05:45 PM
In looking about XML parsers, I found what I needed at XML.com



$article = $_SERVER["HTTP_REFERER"];

$instr = file_get_contents($article);
//Mark the beginning and the end
$pos["artstart"] = stripos($instr,"<!---BEGIN--->");
$pos["artend"] = stripos($instr,"<!---END--->")+13;
//Get what's in between
$input["article"] = substr($instr,$pos["artstart"],$pos["artend"]-$pos["artstart"]);


And then put <!---BEGIN---> at the beginning of the article and <!---END---> at the end. Very simple. Thanks for helping me get started on the right track.

aceofspades
02-07-2007, 08:25 PM
ok watever you prefer. Good luck.

God's Webmaster
02-17-2007, 06:29 PM
I discovered, when I uploaded the script to my website running PHP 4, that stripos() does not work with PHP 4 (I had tested it using PHP 5 on my computer). But in the PHP manual, I found this code, which creates stripos() if it doesn't exist:



if (!function_exists("stripos")) {
function stripos($str,$needle,$offset=0)
{
return strpos(strtolower($str),strtolower($needle),$offse t);
}
}


Thought that might be helpful for anyone else trying my code.

Joel