Ok guys.. I have a HTML i need to parse into a php script and mangle the data around abit. For best explanation I will show how I would do this in a bash script using awk, grep, egrep, and sed through a god awful set of pipes. Commented for clarity.
curl -s http://myhost.net/mysite/ | \ # retr the document
awk '/\/\action/,/submit/' | \ # Extract only the form element
egrep -v "delete|submit" | \ # Remove the action lines
sed 's/^[ \t]*//;s/[ \t]*$//' | \ # Trim extra whitespaces etc.
sed -n -e ":a" -e "$ s/\n//gp;N;b a" | \ # Remove every line break
sed '{s|<br />|<br />\n|g}' | \ # Insert new line breaks after <br />
grep "onemyndseye@localhost" | \ # Get lines containing my local email
sed '{s/\[[^|]*\]//g}' | \ # Remove my email from the line
These commands take the form element that looks like this:
<form action="/action" method="post">
<input type="checkbox" id="D1" name="D1" /><a href="http://www.linux.com/rss/feeds.php">
http://www.linux.com/rss/feeds.php
</a> [email:
onemyndseye@localhost (Default)
]<br />
<input type="checkbox" id="D2" name="D2" /><a href="http://www.ubuntu.com/rss.xml">
http://www.ubuntu.com/rss.xml
</a> [email:
onemyndseye@localhost (Default)
]<br />
<input type="submit" name="delete_submit" value="Delete Selected" />
And mangles it into complete one-line input statements.. Ready to be inserted into another form:
<input type="checkbox" id="D1" name="D1" /><a href="http://www.linux.com/rss/feeds.php">http://www.linux.com/rss/feeds.php</a> <br />
<input type="checkbox" id="D2" name="D2" /><a href="http://www.ubuntu.com/rss.xml">http://www.ubuntu.com/rss.xml</a> <br />
The big question is how to accomplish this in PHP? I am comfortable with using PHP to curl a page... but it seems I am lost on filtering the output.
Thanks in advance. :)