从URL中删除文本

时间:2011-09-08 20:45:34

标签: php strip

我试图剥离find_loc =和& cflt =披萨我得到了大多数剥离它只是这些最后2件事情,每当我尝试使用修剪它不会删除它它一直说数组甚至当我尝试打印它,它说阵列。

<?php
    $foo = 'http://www.yelp.com/search?find_loc=2190+W+Washington+Blvd%2C+Los+Angeles+90018&cflt=pizza ';

    $blah = parse_url($foo);

    $blah[query];

//the code above echos out find_loc=2190+W+Washington+Blvd%2C+Los+Angeles+90018&cflt=pizza

    $thids = trim(''.$blah.'','find_loc=');

    echo $thids;
    ?>

2 个答案:

答案 0 :(得分:2)

$thids = str_replace(array('&cflt=pizza','find_loc='), '', $blah);

答案 1 :(得分:1)

parse_str($blah['query'], $query_vars); // decompose query string into components

unset($query_vars['find_loc']); // delete this particular query variable/value
unset($query_vars['cflt']);

$blah['query'] = http_build_query($query_vars); // rebuild the query string

$foo = http_build_url($blah); // rebuild the url