• barbarac

    (@barbarac)


    Hi,

    I am trying to pass the value of “the_permalink();” in my index.php file into a split function but cannot seem to get the results that I need.

    Basically I want to use everything after “=” in another function.

    What am I doing wrong?

    <?php
    $testLink = the_permalink();
    echo $testLink;
    $query = split( “=”, ($testlink));
    $number = $query[1];
    echo $number;
    ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • ifelse

    (@ifelse)

    split is really the wrong function to use in this instance. Split breaks up a string into array. What you are asking for is the substring of everything after your delimiter ‘=’.

    First you’ll need to find the position of the delimiter.
    $pos = strpos($testLink,'=');
    Now, using this offset, we can get everything after it.
    $number = substr($testLink, $pos);

    However, whilst this is what you asked for, this may not be what you are looking for. This may, on ocaasions, get you a load of unrelated info e.g. if the reader does a search.

    You can get what you want with the following:
    $number= $_GET['p'];

    This will allow you to get the value of the get variable p that is passed in the query string.

    Thread Starter barbarac

    (@barbarac)

    Thanks ifelse,

    However on the page that I am using I am not getting the permalink form the URL but from the “the_permalink();”

    Here is how I’ve implemented what you suggested
    <br>**********************************<br>
    <?php
    $testLink = the_permalink();
    $pos = strpos($testLink,’=’);
    $number = substr($testLink, $pos);
    echo $number;
    ?>
    <br>**********************************<br><br>

    and here is how its parsing
    http://www.cafegeek.com/home/

    Kafkaesqui

    (@kafkaesqui)

    Use get_permalink() to return the permalink as a value to assign to your $testLink var.

    ifelse

    (@ifelse)

    the_permalink echoes the permalink url. I think what you’ll need is get_permalink()

    ifelse

    (@ifelse)

    Kafkaesqui got there first… should have clicked refresh before posting:-)

    Thread Starter barbarac

    (@barbarac)

    Awesome. Thanks to all for the help!!

    Here is the final code for reference:

    <?php
    $testLink = get_permalink() ;
    $query = split( “=”, $testLink);
    $number = $query[1];
    echo rate($number);
    ?>

    You’ll note that I have passed the data into the great ratings function from http://www.phpsoft.org/.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Basic PHP Question’ is closed to new replies.