How to add different text after echo output using PHP

81 views Asked by At
$DOM = new DOMDocument();

@$DOM->loadHTML($html);

$finder = new DomXPath($DOM);

$classname = 'winning-numbers';

$nodes = $finder->query("//*[contains(@class, '$classname')]");

 foreach ($nodes as $node) {
echo "<p>","<b>11 AM Draw:","\n",$node->nodeValue,"</b>","</p>";

// I add paragraph and bold tags on the echo output but this site recognize the tags.

}

I'm almost done with it. The problem is I want to output like this

 11 AM Draw: 111(just an example value)
 4 PM Draw: 222(just an example value)
 9 PM Draw: 333(just an example value)

but I'm getting this

11 AM Draw: 2-2-0
11 AM Draw: 7-7-2
11 AM Draw: 1-6-1
1

There are 1 answers

10
OllyBarca On BEST ANSWER

Use the str_replace function to find and replace characters in your string:

$time = array('11 AM', '4 PM', '9 PM');
$i = 0;
foreach ($nodes as $node) {
    echo "<p><b>".$time[$i]." : ".str_replace("-","",$node->nodeValue)."</b></p>";
    $i++;
}