web hosting
build a website

PHP replace a string in an array with a string

Aug 15, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

The below code sets getImageUrl as the variable $baseimageurl it then gets anything in $baseimageurl uses it in an array and says if it is a http:// or https:// replaces it with a blank “”

So what this means is if $baseimageurl starts with http:// or https:// it removes it so that the link will probably only start as www.

$baseimageurl = $_product->getImageUrl();
echo "\n&viewed-image=" . str_replace(["http://", "https://"],"",$baseimageurl);