Need a halp!PHP homework!
Posted: Wed Feb 03, 2010 11:05 am
Plese I need that for morning for tomorrow!
Thanks!
2. You have been asked to do some textual analysis of html code programatically. Given HTML code as input please provide answers to the following:
a) Write a php function which will take as input a parameter containing random html code. Examine the code and extraxt the text from the deepest nested tag fount in the code. Example:
INPUT:
$x= '
Hello there. <p> Today it was a <b>beautiful</b> sunny day in <a href="http://israel.co.il">Tel Aviv</a> sea shore. Having come from a <span class="newtext">country which does not have a sea <span class="more"> <br />I found it very interesting to look at the <strong>waves</strong></span> smashing <b>against</b> the </span>walls of the harbour</p>
'
foo($x);
OUTPUT
waves
b) Please write a php function which will take a html code as parameter and output the nesting level of each tag in their order of appearance preceeded by the tag name. For example for input from a) the result would be:
p -> 1
b -> 2
a -> 2
span -> 2
span -> 3
br -> 3
strong -> 4
b -> 2
Thanks!
2. You have been asked to do some textual analysis of html code programatically. Given HTML code as input please provide answers to the following:
a) Write a php function which will take as input a parameter containing random html code. Examine the code and extraxt the text from the deepest nested tag fount in the code. Example:
INPUT:
$x= '
Hello there. <p> Today it was a <b>beautiful</b> sunny day in <a href="http://israel.co.il">Tel Aviv</a> sea shore. Having come from a <span class="newtext">country which does not have a sea <span class="more"> <br />I found it very interesting to look at the <strong>waves</strong></span> smashing <b>against</b> the </span>walls of the harbour</p>
'
foo($x);
OUTPUT
waves
b) Please write a php function which will take a html code as parameter and output the nesting level of each tag in their order of appearance preceeded by the tag name. For example for input from a) the result would be:
p -> 1
b -> 2
a -> 2
span -> 2
span -> 3
br -> 3
strong -> 4
b -> 2