I would recommend you to use key value pairing concept. However the assumption lies that key would be unique. Its known as Hash Map data structure. In the article cited below its explained how you can do key-value implementation in php using arrays.
Question
Here's the code:
$search = $data->find("div.box_rezult");
if($data->innertext!="" and $search ){
$index = 1;
foreach($search as $box_rezult) {
echo "<div id=\"header_".$index."\" class=\"headings\">".$box_rezult->find("td.l_name", 0)->plaintext;
echo "<br/>";
Now I need to replace some words that the code parses from the html-page. For example, if there are words "flowers" and "roses" I want them to be changed to "yellow" and "red".
I'm using the code below but it doesn't work. Correct me please. Thanks!
$search = $data->find("div.box_rezult");
if($data->innertext!="" and $search ){
$index = 1;
foreach($search as $box_rezult) {
$phrase = $search->plaintext;
$flowers = array("flowers", "roses", "snowdrop");
$color = array("yellow", "red", "white");
$newphrase = str_replace($flowers, $color, $phrase);
echo "<div id=\"header_".$index."\" class=\"headings\">".$box_rezult->find("td.l_name", 0)->plaintext.$newphrase;
echo "<br/>";
Solution
OTHER TIPS
This is pretty much the kind of code that gives PHP a bad name. Let's just focus on the part you care about:
$flowers = array("flowers", "roses", "snowdrop");
$color = array("yellow", "red", "white");
$newphrase = str_replace($healthy, $yummy, $phrase);
$healthy
and $yummy
are undefined. Done. Watch your logs.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow