I have a problem... I want to know if the URL or TITLE in my XML file is containing some specified keywords. If yes, they should be added to the specified product. If no, a "Nothing" should be added to the specified product.
But my problem is that I don't have the knowledge to programm it so, that the program checks if the keywords from the array are in the URL or TITLE. Because if not the first keyword of the array is in the URL or TITLE it will always go into the else tribe and add "Nothing"...
How can I say that the progamm is only allowed to add "Nothing" if the program checked the 7 keywords in the $searches
array?
Also the program must consider that the keyword values above 3 should be saved as "PlayStation" and not as "PS3", "PS4" or "PSN"!
And in addtion, how can I add them to my prodcuts? - I don't think that my code below is doing that...
Code:
$searches = ["Steam", "Uplay", "Xbox", "Nintendo", "PS3", "PS4", "PSN"];
function isContaining($searches, $titleTag, $urlTag, $productTag, $path){
$dom = new DOMDocument('1.0', 'utf-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->load($path);
$root = $dom->documentElement;
$markerTitle = $root->getElementsByTagName($titleTag);
$markerURL = $root->getElementsByTagName($urlTag);
$plat = array();
for($i = $markerTitle->length - 1; $i >= 0 ; $i--){
$title = $markerTitle->item($i)->textContent;
$url = $markerURL->item($i)->textContent;
$co = count($searches);
for($j = 0; $j < $co; $j++){
if(stripos($title, $searches[$j]) !== false){
if($j > 4){
array_push($plat, "PlayStation");
}elseif($j < 5){
array_push($plat, $searches[$j]);
}
}elseif(stripos($url, $searches[$j]) !== false){
if($j > 4){
array_push($plat, "PlayStation");
}elseif($j < 5){
array_push($plat, $searches[$j]);
}
}elseif($j == 7 && stripos($url, $searches[$j]) == false){
array_push($plat, "Nothing");
}
}
}
array_reverse($plat);
print_r($plat);
$c = count($plat);
for($i = 0; $i < $c; $i++){
$node = $dom->createElement('plat', $plat[$c]);
$dom->getElementsByTagName($productTag)->item($i)->appendChild($node);
}
$dom->saveXML();
$dom->save($path);
}
isContaining($searches, "name", "link", "product", $gamesplanetPath);
Greetings and Thank you!