PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Aug 24, 2017 12:02 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Preg_match_all
PostPosted: Sat May 27, 2017 2:01 am 
Offline
Forum Newbie

Joined: Sat May 27, 2017 1:43 am
Posts: 1
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:
Syntax: [ Download ] [ Hide ]
<?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/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group