Hello ,

I'm trying to split a string using preg_split() ( since split ) is deprected...
I'm trying to split it using '=' sign and to get the GETS variable from a url but I'm getting the error :
"Warning: preg_split() [function.preg-split]: No ending delimiter '=' found in C:"

The code is :
<?php

$request_url = $_SERVER;

//parse the page request and get variables
$parsed_url = explode('&',$request_url );


$page_is = array_shift($parsed_url );

$getVars = array();
foreach($parsed_url as $argument)
{
//split GET vars along '=' symbol to separate variables and values
list($variable,$value) = preg_split("=",$argument);
$getVars[$variable] = $value;
}

//this is a test and we will be removing it later
print "the page you requested is '$page_is'";
print '<br>';
$vars = print_r($getVars,TRUE);
print "The following GET vars were passed to the page:<pre>".$vars."</pre>";

?>

Recommended Answers

All 2 Replies

Weird way to get the GET params. Try this:

<?php
foreach ($_GET as $key => &$val) $val = filter_input(INPUT_GET, $key);

foreach ($_POST as $key => &$val) $val = filter_input(INPUT_POST, $key);
?>

or see this page: http://php.net/manual/fr/reserved.variables.get.php

Withing preg_split you should use a regular expression to split. An regular expression string starts with a character that also has to close the string. e.g. "!=!". In your case PHP thought the = was that character.

Hi. Thanks for the reply . I used "!=!" insted of "=" and didnt got the error.
Issue solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.