How do I reformat a variable in PHP, I need help doing it three different ways.?

  • Thread starter Thread starter truepaige
  • Start date Start date
T

truepaige

Guest
Hello everyone,

I'm trying to take a variable and then reformat it in a few ways for a few different uses, and am hoping you can assist me. =)

The variable I have is, for example:

$recipe = "Artichoke Pasta Salad"

I need to use this variable in a few ways.
------------------------------




I need to format it making the space a %2C+:

Artichoke%2C+Pasta%2C+Salad





I also need to take just the first word so I can use it in places where a full search wouldn't work, so just grabbing the word:

Artichoke





Finally, I need to format it as:

Artichoke+Pasta+Salad


------------------------------
I know this might be a bit of a tall order, but a little help would go a long way for me. Please if you can assist, I would appreciate it very much. Thank you.
 
$recipe1 = str_replace(" ", "%2C+", $recipe);

$words = explode(" ", $recipe);
$firstWord = $words[0];

$recipe2 = str_replace(" ", "+", $recipe);
 
Back
Top