duanpa1980 2019-03-01 10:47
浏览 84

URL中的变量

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 ;)

  • 写回答

3条回答 默认 最新

  • doxp30826 2019-03-01 10:56
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示