Log in

View Full Version : PHP Help needed.



tgallagher26
04-27-2009, 08:26 PM
Ok so I am trying to get the Related Search terms from MSN Live and put them on my site with my links.

Here is the test code I am using.


<?php
include 'simple_html_dom.php';
$html = file_get_html("http://search.live.com/results.aspx?q=house&form=QBLH");
foreach($html->find('div[class=qscolumn]') as $related) {
foreach($related->find('li') as $related2)
echo '<a href="http://kywordpro.com/txt/1/10/' . $related2->plaintext . '.html" target="blank">' . $related2->plaintext . '</a><br /> ';
}
?>

It works fine as you can see on my test page (http://www.kywordpro.com/test.php)

The problem is I want to use this code with it


$search = array(' ', '&','(',')',',','%');
$replace = array('+', '%26','%28','%29','%2C','%25');
$subject = $related2;
$relatedurl= str_replace($search, $replace, $subject);

To make the links internet freindly

so my complete code would be


<?php
include 'simple_html_dom.php';
$html = file_get_html("http://search.live.com/results.aspx?q=house&form=QBLH");
foreach($html->find('div[class=qscolumn]') as $related) {
foreach($related->find('li') as $related2)
$search = array(' ', '&','(',')',',','%');
$replace = array('+', '%26','%28','%29','%2C','%25');
$subject = $related2;
$relatedurl= str_replace($search, $replace, $subject);
echo '<a href="http://kywordpro.com/txt/1/10/' . $relatedurl->plaintext . '.html" target="blank">' . $related2->plaintext . '</a><br /> ';
}
?>

The problem is when I use teh code as a whole it only displays the last array.

Can anyone help?

Tim...