View Full Version : Split and search
XAKERA
03-17-2008, 09:31 AM
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.
city_coder
03-17-2008, 10:24 AM
What do you mean split? Is it an array of some sort? or just a string that is comma delimited?
alexjewell
03-17-2008, 10:50 AM
Use explode to "split" the string at every comma:
$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).
Boxer
03-17-2008, 12:59 PM
<?
$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";
?>
XAKERA
03-17-2008, 07:40 PM
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";
Master_script_maker
03-17-2008, 08:11 PM
$artist = ... You're rewriting the string over and over. Right code:
$atrist[] = ...
XAKERA
03-17-2008, 08:27 PM
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>";
Master_script_maker
03-17-2008, 08:42 PM
$artist .= ...
XAKERA
03-18-2008, 06:43 AM
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>, ";
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
XAKERA
03-18-2008, 04:05 PM
doesn't exist another way to make it? not with foreach
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.