PHP - Extracting Information From Utmz Cookie
Hi All,
I'm new and don't have that much experience in php. So i thought I would ask for some help. I am trying to get some information from the Google Analytics cookie utmz so I can track customers better. I know there is code to do this, but I'm seeing a lot of conflicting this around the net. The info I would like to pull out is Source Medium Keyword I would like to then place this on an email when a form is filled out. This helps me understand which terms are converting into sales. Is anyone able to help? Thank you in advance Colin Similar TutorialsMorning all, I hope I'm posting this in the correct section - if not, please feel free to move it. What I'm trying to do is extract keyword information from the Google Analytics cookie and pass it into the header when a click is generated. Having hunted around I understand that I need to extract the utmctr value from the __utmz campaign cookie, which looks like this: So here's a short function that I wrote to try and extract the keyword information: function parse_ga_cookie($cookie) { $values = sscanf($cookie, '%d.%d.%d.%d.utmcsr=%[^|]|utmccn=%[^|]|utmcmd=%[^|]|utmctr=%[^|]'); if (count($values) !== 8) { // return false; trigger_error(...); ... or whatever you like throw new InvalidArgumentException("Cookie value '$cookie' does not conform to the __utmz pattern"); } $keys = array('domain', 'timestamp', 'visits', 'sources', 'campaign', 'source', 'medium', 'keyword'); return array_combine($keys, $values); } // Cooookkkkkkiiiiiiieeeeeeeeeeee, om nom nom... $keyword=(parse_ga_cookie($_COOKIE['__utmz'])); Unfortunately though when I go to print out the value $keyword I'm just getting the value 'Array' Is anyone able to help me out at all here? I can't see where the problem lies. Thanks a lot for your help ... Folks, I want to extract certain portion form URL. Exmaple: Quote http://abc.com/this-is-test.html Output should be Quote this-is-test Another Example Quote http://abc.com/this-is-yet-another-test.html Output should be Quote this-is-yet-another-test I am not sure how it can be done with preg_match() and regex or something like that... Can someone help me with this please? Cheers Natasha I have an RSS feed, with alot of data of lottery numbers. the feed itself is : http://www.alllotto.com/rss/NY/latest.rss The item i am interested in is: Quote <item> <title>Take 5</title> <description>2011-08-27: 4, 10, 16, 17, 31</description> <guid isPermaLink="false">USA-New-York-Take-5-2011-08-27</guid> </item> How could I output those to varibles? thanks Joe I'm *attempting* to write a script that will take a paste of data from a user and when it's submitted it will drop certain parts of the data into databases and be available for recall later. I have the MySQL sorta out I think but I can't test until I get this part done. Basically people will paste a copied paste (CTRL A, CTRL C and go to my form and just hit CTRL V). It will contain a bunch of data I want to drop in the database but in different areas, like the following example the items in bold are the items I want to grab. First Name: Lincoln Last Name: Coe Address: 1234 Easy St, Perfectville, PV 00000 Telephone: 0000000000 I usually only do design work, but a client wanted a log in system to his website, so I decided to do it. I set everything up correctly, and users can sign up, login, and log out. However, he wants to be informed when a user logs into his site. So say (user x) wants logs in, my client wants to receive an email with all of (user x)'s account information. How do I pull a row from mysql based on the login information provided? My database is has 7 columns: user, pass, name, address, state, phone, email Hey guys i have a array i made and im wanting to grab a random value out of the array. The only way i can see to do this looking at the list of array functions is i need to random a key first? and then return the value assigned to the random key i just generated? I only see a function that lets me do the opposite. array_search() so now that i have generated a random key how do I grab just the value from the array using the random key. or is there a function i can just random value? $explode_names = explode(" ", $planet_names); $random_key_name = (array_rand($explode_names, 1)); echo $random_key_name; $example "Q: Example? A:" Let's assume that I'd like to display $example but exclude "Q:" and "A:", how would I do that? Hi there I need to extract data from some XML. I have found a few sites that explain that part to me, however there is a section of the data which I need to extract and am not sure how to go about it. Below is an extract of the XML, the section I am trying to extract is highlighted in red (it is essentially a text message being sent I am trying to get the contents of the sms/text message): <usa_smpp_host>THTTP</usa_smpp_host> <short_message>id:660352946 sub:001 dlvrd:001 submit date:1102081032 done date:1102081035 stat:DELIVRD err:000 text:Test SMS message</short_message> <dest_addr_npi>1</dest_addr_npi> Any assistance would be appreciated. Have played around quite a bit but have not managed to figure it out yet. thanks HI guys, I'm quite new to php, and I'm really struggling to get this right. I just cant get it to work properly. Im trying to extract email from a list of URLS. I have currently got it to work with 1 URL at a time, but I am needing to as to how I can pass multiple URLS at once, either from a csv or just pasting them into the input. any help would be much appriciated. here is my current code: Quote <?php $the_url = isset($_REQUEST['url']) ? htmlspecialchars($_REQUEST['url']) : ''; ?> <form method="post"> Please enter full URL of the page to parse (including http://):<br /> <textarea name="url" cols="100" rows="10"><?php echo $the_url; ?></textarea> <br /> <input type="submit" value="Get Emails" /> </form> <?php if (isset($_REQUEST['url']) && !empty($_REQUEST['url'])) { // fetch data from specified url $text = file_get_contents($_REQUEST['url']); } elseif (isset($_REQUEST['text']) && !empty($_REQUEST['text'])) { // get text from text area $text = $_REQUEST['text']; } // parse emails if (!empty($text)) { $res = preg_match_all( "/[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i", $text, $matches ); if ($res) { foreach(array_unique($matches[0]) as $email) { echo $email . "<br />"; } } else { echo "No emails found."; } } ?> hey guys i need to extract all the IP's of a string and loop them for more operations but for some reason i only get the first one <?php $string = '80.37.14.13 80.37.14.14 80.37.14.15'; preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $string, $matches); foreach ($matches as $ip){ echo "$ip<br>"; } ?> The string is not really seperated by spaces ... it can actualy be messy and have ips rapped arround a lot of code. The regex works because i do get the first one ... What did i miss? I have a string that looks like /index.php?g1=111&g2=222&g3=333. How can I obtain the value of g1 (i.e. 111)? It does not represent the current state of the server thus I cannot just use $_GET. It also is not necessarily the first item. The script below appears to work, however, http://php.net/manua...n.parse-url.php states This function is intended specifically for the purpose of parsing URLs and not URIs. However, to comply with PHP's backwards compatibility requirements it makes an exception for the file:// scheme where triple slashes (file:///...) are allowed. For any other scheme this is invalid. It appears that my string is a URI and not a URL, but I might be wrong. How should this be accomplished <?php $str='/index.php?g1=111&g2=222&g3=333'; $array=parse_url($str); parse_str($array['query'],$get); echo("<p>{$get['g1']}</p>"); ?> Folks, I want to extract the keywords Only form the below Script's output: <?php $keywords = file_get_contents('http://suggestqueries.google.com/complete/search?hl=en&gl=us&ds=pr&client=products&hjson=t&jsonp=ac_hr&q=paintball&cp=2'); //$keywords = json_decode($keywords); print_r($keywords); ?> Output is: ac_hr(["paintball",[["paintballs","","0"],["paintball sniper","","1"],["paintball mask","","2"],["paintball vest","","3"],["paintball pants","","4"],["paintball bunkers","","5"],["paintball markers","","6"],["paintball chronograph","","7"],["paintball bow","","8"],["paintball helmets","","9"]],"","","","","",{}]) How to extract the keywords Only in an Array?? Cheers Natasha T I am trying to extract field data from a specific row, Here is my code: $query = "SELECT * FROM music WHERE title = '%$selected%'"; $musicresult = mysql_query($query) or die ("Couldn't execute query."); $row = mysql_fetch_array($musicresult); /* extract the contents of the row */ Line 98 extract($row); echo $title." "."<BR>"; echo $select."<BR>"; /* set contents of selected to 1 */ $selectval = $select; ++$selectval ; echo $selectval."<BR>"; /* Put the data into the database */ //$query= "UPDATE music SET select=$selectval WHERE title=$selected"; //$result = mysql_query($query) or die ("could not save new data!"); Here is the error message: Warning: extract() [function.extract]: First argument should be an array in /home/content/a/c/k/acksfaq/html/theackshow/THANKYOU.PHP on line 98 The two echo statements that follow line 98 do not generate an output About the only thing that is different with is table compared with a table that this code works with is the fact that this table (music) is not indexed. What the heck am I doing wrong?? Thanks, Ack Hi Ive been trying to solve this problem for a few hours but am having no luck so would appreciate any help Im looking for a function/way of extracting info from a dropdown list when a form is submitted. The form field has a name and email address i.e John (john@smith.com) and i just need the email address part to submit into a mysql database. I tried using the explode() function but this didnt work. Any ideas? Cheers Andy I have 2 sites. 1 site is a store the other is a blog. The homepage of the store shows random product images. Each image links to it's product page. I'm using the code below to get data from the store homepage into a variable: Code: [Select] <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.somesite.com"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); ?> I can echo $output and see the page displayed on my page. So that part is working. On the blog, I want to display random products and link them back to the store. How can I extract just the images & their page links from the $output variable? Morning all, I am wondering whether there is a way (I am sure there is!) to extract the full website address with any GET variables in it also. Basically, I am trying to extract the website address and add another $_GET['var'] to it. Something like. example web address: http://www.website.com/index.php?type=abc <?php $address = // Extract the current website address here. $newvar = "?model=123"; $link = $address.$newvar; echo '<a href="$link">Click here to add a variable</a>'; ?> Hi, not sure if this is posted in the right place (think it should be in the Regex section ) but hopefully someone can help me out a bit. I have the following string for example which is stored in a variable called $var. Quote This is a reference [ref=17][/ref] number I wish to extract only the number after the equals sign and store it as a variable. So I am using the following code to do so: $ref_num = preg_replace("/.*?\[ref\=(.*?)\]\[\/ref\].*?/is", "$1", $var); The only problem is, I can omit the text before the integer and the tags themselves but I still get the text after the [/ref] section and I cannot get rid of it. It seems my .*? placed after it doesn't work like it does at the beginning. Can anyone offer any help at all, it will be greatly appreciated - I'm fairly new to using Preg_replace so I still don't know how best to form Regular Expressions. Thanks, Dan EDIT- I have found a workaround which I will post below - however I would still like to solve it the way I planned originally which is the way I posted here. Here's what I did - because I know the integer is never going to be more than 5 characters long, I used the replace from before but added a substring like so. $ref = substr(preg_replace("/.*?\[ref\=(.*?)\]\[\/ref\]/is", "$1", $var),0,5); This grabbed the first 5 characters whether it was a number or not, then I used this to strip any non-numerical characters. Finally I added an intval to convert it to an integer rather than a string. $ref = intval(preg_replace ('/[^\d\s]/', '', $ref)); Hi - I have an array where one of the values delivers a string. Here is the output from a print_r($pickupdates): Code: [Select] Array ( [0] => Array ( [location] => Clearwater [TheDates] => 1311746700,1321746641,1331668779 ) [1] => Array ( [location] => Canmore [TheDates] => 1311746700,1321746641,1331746641 ) [2] => Array ( [location] => Collingwood [TheDates] => 1311746700,1321746641,1331746641 ) [3] => Array ( [location] => Varsity [TheDates] => 1321746641,1330746700,1331746700 ) The challenge is to get the location and TheDates into a nice HTML table which would look like this: Code: [Select] LOCATION DATE 1 DATE 2 DATE 3 Clearwater April 1 May 1 June 1 Varsity April 2 May 2 June 2 Collingwood April 3 May 3 June 3 Canmore April 4 May 4 June 4 Ok - Now I am stuck, I need to be able to uniquely identify each date that is associated with the location such that I can run a foreach() on then so I can populate the table properly. I tried using list() and explode. List does not separate the dates and explode needs a string not an array. I'm really stuck - a very big Heartfelt thanks to anyone who can steer me in the right direction. MANY THANKS ! I'm normally fairly proficient with PHP, but I haven't done any coding in quite a while, so I'm a little rusty. I have an entire page of text from which I need to extract a single value. Here is a small portion of the page in question: Code: [Select] Total Rank: 128 Total Points: 4,978 Next Rank: 20 For instance, I need to extract the values "128" "4978" and "20" and store them in variables. These values change all the time, so I'm not sure what the best way to go about this is... maybe a regular expression ? If that's the case, I've never been too good with them, so any help would be appreciated. |