1

I have a search form in my page where a user submits a query. The form is submitted and the search query is submitted in the browser's url. The PHP searches and return the result. E.g. http://example.com/search-results.php?q=ABC+books

The result page has its own independant search form which includes the text box. I use $_GET['q'] to get the text in the input box which displays ABC books.

The problem is when I use search queries that contain characters like an apostrophe ('). E.g. when I search Marley's Bar the URL would be - http://example.com/search-results.php?q= marley%27s+bar The outputted text in the input box displays marley\'s bar I would like to return the value as 'marley's bar' without the slash.

I tried

$getSearchQuery = $_GET['q'];
$getSearchQuery = rawurldecode($getSearchQuery);

but the output is still the same.

xltmt
  • 61
  • 7

1 Answers1

1

Friend I think you're looking for this

Example #1 A stripslashes() example

<?php
$str = "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>

Example #2 Using stripslashes() on an array

<?php
function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('stripslashes_deep', $value) :
                stripslashes($value);

    return $value;
}

// Example
$array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar"));
$array = stripslashes_deep($array);

// Output
print_r($array);
?>

Please have look at source

Kaleem Ullah
  • 6,799
  • 3
  • 42
  • 47