I'm making a website with wordpress for my company and i have a question for you
I have an url like this
http://mysuperwebsite/?_sft_category=cx+ms+lol
And i would like to grab the argument of this, so i tried
$motsclefs = $_GET['_sft_category'] ;
and a basic echo
echo'<div>'.$motsclefs.'</div>';
This is cool but now this return me something like this in a single div
cx ms lol
My desire is to cut those words, to have as much div as my words
To be more specific i would like to have something like this
<div class="1">cx</div>
<div class="2">ms</div>
<div class="3">lol</div>
So, i understood that i have to consider those "+" in the url to separate my words ?
Thanks ;)
You can split the string by a space, if $motsclefs is a string with spaces separating the arguments, which is how it looks from your question:
$arguments = explode(" ", $motsclefs);
Then iterate through them:
foreach ($arguments as $argument) {
echo "<div>$argument</div>";
}
For different classes;
$i = 1;
foreach ($arguments as $argument) {
echo "<div class='class$i'>$argument</div>";
$i++;
}
$i
increases for each loop round which will give you a new number with every iteration.
You can try this.
$tempArr=explode(' ',$motsclefs);
for($i=0;$i < count($tempArr);$i++)
{
echo '<div>'.$tempArr[$i].'</div>';
}
As mentioned by Jon Stirling use explode and foreach.
<?php
$motsclefs = 'cx ms lol';
$divs = '';
foreach(explode(' ', $motsclefs) as $key => $element) {
$divs .= sprintf ('<div class="%s">%s</div>' . PHP_EOL, $key + 1, $element);
}