Page 1 of 1

Preg_match_all

Posted: Sat May 27, 2017 2:01 am
by damian0021
On my site wants to change data on the fly (Wordpress).

So that the name of the product was downloaded from the page code and was auto-injected into Even GA.

I created this code:

Code: Select all

<?php

function w_callback($b){

$what = $on = array();
$what_r = $on_r = array();

	preg_match_all('~<span class="Tytul">([^<]*)</span>~Usmi', $b, $dane_wejsciowe_nazwa_dopasowania); 
	foreach ($dane_wejsciowe_nazwa_dopasowania[1] as $key) { 
		$what_arr[] .= 'class="Offer">'; 
		$on_arr[] .= 'itemscope="" itemtype="http://schema.org/Offer" onclick="ga(\'send\', \'event\', \''.$_SERVER['REQUEST_URI'].'\', \''.$key.'\');" class="Offer">';		
	}

    $b = str_replace($what,$on,$b);
    $b = preg_replace($what_r,$on_r,$b);  
    $b = str_replace($what_arr, $on_arr, $b);    


return $b;
}
if(stristr($_SERVER['REQUEST_URI'],'wp-admin')===false) ob_start('w_callback');
?>

The name of the product is taken and thrown into place, but everywhere is generated the same.
Image


Online: http://seowars.cba.pl/2017/05/26/witaj-swiecie/