Results 1 to 10 of 10

Thread: Split and search

  1. #1
    Join Date
    Dec 2007
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Split and search

    how make it when split make <a href=php.php?artist=$split_name:
    example artist is: Georgia Mickle, Kate Melua, 50Cent, Akon.
    First Split is Goergia Mickle
    seccont split is Kate Malue
    Third split is Akon.
    Than when someone click on Georgia Mickle search it by this name.

  2. #2
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default

    What do you mean split? Is it an array of some sort? or just a string that is comma delimited?
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

  3. #3
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Use explode to "split" the string at every comma:

    PHP Code:
    $string 'Georgia Mickle, Kate Melua, 50Cent, Akon';
    list(
    $mickle,$melua,$cent,$akon) = explode(', ',$string); 
    So then the variable $mickle will correspond with Georgia Mickle, $melua with Kate Melua, and so on. List them in order of where they're split, then explode the string by a specific character (spaces will even work, as well).
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  4. #4
    Join Date
    Dec 2007
    Posts
    6
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    PHP Code:
    <?
    $string 
    'Georgia Mickle, Kate Melua, 50Cent, Akon';
    $parts explode", "$string );

    foreach( 
    $parts as $part ) echo "<a href=\"search.php?artist=" strtr$part" ""+" ) . "\">$part</a> \n";
    ?>

  5. #5
    Join Date
    Dec 2007
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thank Boxer but when i make it like this only shows me One string
    $string = 'Georgia Mickle, Kate Melua, 50Cent, Akon';
    $parts = explode( ", ", $string );

    foreach( $parts as $part ) $artist = "<a href=\"search.php?artist=" . strtr( $part, " ", "+" ) . "\">$part</a> \n";

  6. #6
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    $artist = ... You're rewriting the string over and over. Right code:
    $atrist[] = ...
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  7. #7
    Join Date
    Dec 2007
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    than it writes me 'array'. i put it like this:
    $artistsrt = explode( ", ", $row["artist"]);
    foreach( $artistsrt as $part )
    $artist[] = "<a href=\"#\" onclick=chatvirte(this); url=search.php?artist=" . strtr( $part, " ", " " ) . " rel=main_div>$part</a>";

  8. #8
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    $artist .= ...
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  9. #9
    Join Date
    Dec 2007
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks but doesn;t work:
    I put this: $artist .= "<a href=\"#\" onclick=chatvirte(this); url=search.php?artist=" . strtr( $part, " ", "" ) . " rel=main_div>$part</a>,&nbsp;";
    than in one table shows correct but in another table repeat old artist+her artist.
    ex. first line is 'Georgia Mickle, Kate Melua, 50Cent, Akon', Second table are 'Georgia Mickle, Kate Melua, 50Cent, Akon, Checker, Global, Mp3'. in seccond line it must be "Checker, Global, Mp3" How correct it

  10. #10
    Join Date
    Dec 2007
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    doesn't exist another way to make it? not with foreach

Bookmarks

Posting Permissions

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