PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jannik
Forum Newbie
Posts: 4 Joined: Wed Dec 08, 2010 2:47 pm
Post
by jannik » Wed Dec 08, 2010 2:59 pm
Hi
when i write
it says:
Cat - Subcat
I only want it to show
Subcat
How do I do this codewise? So it ONLY shows what is in the database field AFTER the
-
sign.
Really hope that someone understands my bad english, and can help me.
Thanx in advance.
Jannik
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Wed Dec 08, 2010 3:10 pm
There are many was to do that. Which way is best depends on the expected inputs and outputs.
Here is one example.
Code: Select all
<?php
list ($cat, $sub) = explode(' - ', 'Cat - Subcat', 2);
var_dump($cat, $sub);
/*
string(3) "Cat"
string(6) "Subcat"
*/
jannik
Forum Newbie
Posts: 4 Joined: Wed Dec 08, 2010 2:47 pm
Post
by jannik » Wed Dec 08, 2010 3:24 pm
Hmm dont think u understand what I need.... (my bad)
Perhaps this can help. Just found it by searching google...
opentable($locale['400'].": ".$cdata['download_cat_name'] = substring(download_cat_name, instr(download_cat_name, '-') + 1));
But it doesnt seem to work...
Dont know if I can add the "Substring" inside the Opentable function...
Can you see what i am doing wrong?
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Wed Dec 08, 2010 4:04 pm
You say you have a variable, $data['download_cat_name'], that holds a string. The string is something like "Fruit - Apple" where a category and subcategory are joined by the string " - ".
So,
Code: Select all
list ( , $data['download_cat_name']) = explode(' - ', $data['download_cat_name'], 2);
Does $data['download_cat_name'] not now hold just the subcategory?
jannik
Forum Newbie
Posts: 4 Joined: Wed Dec 08, 2010 2:47 pm
Post
by jannik » Wed Dec 08, 2010 4:34 pm
My code now looks like this
Code: Select all
echo "<a href='downloads.php?cat_id=".$data['download_cat_id']."'>".$strip = strstr($data['download_cat_name'], '-')."</a>";
It works but it still shows the "- " in front. do you know hos to remove those two in this code???
If not I will then try your code tomorrow, will go to sleep now
Thanx in advance.
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Wed Dec 08, 2010 4:46 pm
jannik
Forum Newbie
Posts: 4 Joined: Wed Dec 08, 2010 2:47 pm
Post
by jannik » Wed Dec 22, 2010 7:42 am
Hi. Could someone please help me with the code
I simply can't add the ltrim or trim function.... Pulling my hair off
Could someone please add the trim code to the above code of mine, so that "- " is being removed from the beginning.
Regards
Jannik