English 中文(简体)
• 如何在扼杀实验室的某些特性之后清除一切?
原标题:How to clear everything after certain character in string php?

我几乎没有什么职能使一切的获得和担任职务,但这种职能必须更加具体。

array(
  1 => http://site/something/another/?get_something=1
  2 => http://site/something/another2/?get_something=1
)

还有一个职能,即发挥先天和任人的作用,但这一职能将明确从这些阵列的价值观中的一切内容,这样我就留给我处理。

http://sitesomethinganotherget_something1

can someone please help to match EVERYTHING after get_something= and clear it or replace it with get_something=1 , something like

$clear = preg_match( /^[A-Za-z0-9]+$/ , $array[1]);
preg_replace("/get_something=".$clear."/i","",$array[1]);
最佳回答

您应使用<条码>parse_url<>/code>,但在此过程中,如果你 re:

$urls = array
(
     http://site/something/another/?get_something=1 ,
     http://site/something/another2/?get_something=1 ,
     http://site/something/another/?get_something=1&foo=bar ,
     http://site/something/another/?foo=bar&get_something=1 ,
);

$urls = preg_replace( ~[?&]get_something=.*$~i ,   , $urls);

print_r($urls);

Should output (demo [updated]):

Array
(
    [0] => http://site/something/another/
    [1] => http://site/something/another2/
    [2] => http://site/something/another/
    [3] => http://site/something/another/?foo=bar
)
问题回答

如果你重新尝试用URL加以划分,那么你最好用parse_url<>code>,在你不希望的盘点中排出,并用<代码>重建。 这里我是这样做的:

for($i = 0; $i < count($linkArray); $i++) {
    // get original link and parse it
    $link = parse_url($linkArray[$i]);

    // replace the query portion
    $link["query"] = "get_something=1";

    // build the new URL
    $linkArray[$i] = $link["scheme"] . "://" . $link["hostname"] . $link["path"] . "?" . $link["query"] . "#" . $link["fragment"]

    // done
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...