Results 1 to 8 of 8
  1. #1
    Analytics Dude Kevin's Avatar
    Join Date
    January 18th, 2005
    Location
    Rochester, NY
    Posts
    5,904
    Using PHP to pull a piece of a MySQL field
    I'm having some early successes in my quest to learn reltional DBs and PHP. Here's one that I've searched high and low for, and it's confounding me.

    Here's the content of the field I want to look at:

    ASP.NET_SessionId=kwh0gyeucj2shmuof3uyzvae;+__utma=12312133;+__utmb=xxxxx;+__utmc=xxxxxxx;+__
    utmz=131536920.1232732130.1.1.utmccn=(organic)|utmcsr=live|utmctr=custom+
    binders|utmcmd=organic

    I want to check for either the existance of Organic or GCLID and then pull the bolded part out of the string, and write it to a new table.

    Can PHP select a series of characters after utmctr if that number of characters won't always be constant?

    Can I tell it to grab between = and | ?
    Kevin Webster
    twitter: levelanalytics

    Kayak Fishing
    Web Analytics and Affiliate Marketing

  2. #2
    Member esnagel's Avatar
    Join Date
    January 1st, 2008
    Location
    Buffalo, NY
    Posts
    88
    PHP Code:
    <?php

            $cString 
    'kwh0gyeucj2shmuof3uyzvae;+__utma=12312133;+__utmb=xxxxx;+__utmc=xxxxxxx;+__utmz=131536920.1232732130.1.1.utmccn=(organic)|utmcsr=live|utmctr=custom+binders|utmcmd=organic';

            list( , 
    $cString) = explode('utmctr='$cString);
            list(
    $cString, ) = explode('|'$cString);

            echo(
    "$cString");

    ?>
    Gives custom+binders. You'll just have to get $cString set properly.

  3. #3
    Analytics Dude Kevin's Avatar
    Join Date
    January 18th, 2005
    Location
    Rochester, NY
    Posts
    5,904
    A ha! I'll have to play with this. Thank you.
    Kevin Webster
    twitter: levelanalytics

    Kayak Fishing
    Web Analytics and Affiliate Marketing

  4. #4
    Affiliate Manager
    Join Date
    April 25th, 2008
    Location
    Lexington KY
    Posts
    64
    look at using the strpos and substr functions

    something like

    $value=substr($YourVariable, 0, strpos($YourVariable, $CharacterYouWantToStopAt));

  5. #5
    Full Member Code Monkey's Avatar
    Join Date
    June 11th, 2007
    Posts
    337
    Esnagel, thanks for that bit of code.. I can use it myself..
    Stop blaming the parasites, low return days, cookie stuffers, networks, lousy AMs, and TOOLBARS!

  6. #6
    Affiliate Manager
    Join Date
    April 25th, 2008
    Location
    Lexington KY
    Posts
    64
    Sorry I haven't had enough coffee today

    $value=substr($YourVariable, strpos($YourVariable,'utmctr=')+7, strpos($YourVariable, $CharacterYouWantToStopAt));

    you can also use strpos to test if a string is located in another one, i believe it returns a boolean false if it's not there

    something like

    while (strpos($YourVariable, "organic")) {

    $value=substr($YourVariable, strpos($YourVariable,'utmctr=')+7, strpos($YourVariable, $CharacterYouWantToStopAt));


    }

  7. #7
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    Interestiong solution. I'd have never thought to use explode. It's a clear-cut regular expression case in my mind:
    Code:
    <?php
    $string = "ASP.NET_SessionId=kwh0gyeucj2shmuof3uyzvae;+__utma=12312133;+__utmb=xxxxx;+__utmc=xxxxxxx;+__utmz=131536920.1232732130.1.1.utmccn=(organic)|utmcsr=live|utmctr=custom+binders|utmcmd=organic";
    
    preg_match("/utmctr=(.+)\|/", $string, $match);
    $utmctr = $match[1];
    ?>
    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  8. #8
    ABW Ambassador sjangro's Avatar
    Join Date
    January 18th, 2005
    Location
    Boston
    Posts
    1,529
    Quote Originally Posted by Snib
    Interestiong solution. I'd have never thought to use explode. It's a clear-cut regular expression case in my mind:
    Code:
    <?php
    $string = "ASP.NET_SessionId=kwh0gyeucj2shmuof3uyzvae;+__utma=12312133;+__utmb=xxxxx;+__utmc=xxxxxxx;+__utmz=131536920.1232732130.1.1.utmccn=(organic)|utmcsr=live|utmctr=custom+binders|utmcmd=organic";
    
    preg_match("/utmctr=(.+)\|/", $string, $match);
    $utmctr = $match[1];
    ?>
    - Scott
    Same here. Ironically, the explode is probably faster than preg_match.

    Just goes to show, TIMTOWTDI.

  9. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Using an array from a mysql field in a select statement
    By knight01 in forum Programming / Datafeeds / Tools
    Replies: 9
    Last Post: May 9th, 2010, 10:16 PM
  2. looking for php/mysql work
    By spiderninja in forum Midnight Cafe'
    Replies: 0
    Last Post: January 31st, 2007, 11:12 PM
  3. Php Mysql - Repeating..??
    By AddHandler in forum Programming / Datafeeds / Tools
    Replies: 13
    Last Post: May 7th, 2005, 03:25 PM
  4. Grouping with PHP and MySQL
    By Doug247 in forum Programming / Datafeeds / Tools
    Replies: 3
    Last Post: March 24th, 2005, 10:07 AM
  5. PHP & mySQL but....
    By perfectG in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: November 6th, 2002, 06:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •