2011-09-08 2 views
0

나는 find_loc = 및 &을 제거하려고 시도하고 있습니다. cflt = 피자 저는 대다수가 마지막 2 가지를 벗겨 냈습니다. 그리고 트림을 사용하려고 할 때마다 그것을 삭제하지는 않습니다. 그것을 인쇄하려고하면 어레이라고합니다.URL에서 텍스트를 벗기기

<?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
$thids = str_replace(array('&cflt=pizza','find_loc='), '', $blah); 
+0

그것이 실제로이었다 =) = $ thids 않는 str_replace (배열 ('& cflt = 피자', 'find_loc =') ','$ ㅋ); – user874185

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 
+0

첫번째 줄은'parse_str ($ blah [ 'query'], $ query_vars)이고,'parse_str()은 배열을 반환하지 않습니다. 두 번째 매개 변수로 전달해야합니다. – mcrumley

+0

Arg .. 맞아. 감사. 좋은 캐치. –

관련 문제