Nickool
Nickool

Reputation: 3702

cut array from a specific character

I have this in $array[0]:

attack-responses.rules?rev=1.35&content-type=text/vnd.viewcvs-markup

I want to have this in $array[0]

attack-responses.rules

I mean when it will see '?' it must cut it.

Is there any PHP function?

Upvotes: 0

Views: 67

Answers (2)

KingCrunch
KingCrunch

Reputation: 131931

parse_url()

$array[0] = parse_url($array[0], PHP_URL_PATH);

or list()/explode()

list($array[0]) = explode('?', $array[0], 2);

or substr()/strpos()

$array[0] = substr($array[0], 0, strpos($array[0], '?'))

Upvotes: 4

Shakti Singh
Shakti Singh

Reputation: 86406

look there at the documentation of parse_url

$str="attack-responses.rules?rev=1.35&content-type=text/vnd.viewcvs-markup";
$url=parse_url($str));
$array[0]=$url['path'];

Upvotes: 0

Related Questions