mcan
mcan

Reputation: 2082

Single quotes splits my URls

For example, when i click url below

http://mysite.com/?s=Dominos' books

code below works

$param= $_GET['s'];  
$completeurl = 'http://somesite.com/?param1='.trim($param).'&key=987539873';

So single quote (') in $param splits the $completeurl and i want to keep ' intact.

Altought i replace single quotes (') in $completeurl with double quote (") it doesn't work. How can i prevent this unwanted splittings?

Upvotes: 0

Views: 368

Answers (2)

Teena Thomas
Teena Thomas

Reputation: 5239

try this line:

  $completeurl = 'http://somesite.com/?param1='.str_replace(array("'",' '), '', $param).'&key=987539873';

OR if you want to keep the ' intact

$completeurl = 'http://somesite.com/?param1='.urlencode(trim($param)).'&key=987539873';

Upvotes: 0

Brad
Brad

Reputation: 163603

You need to URL-encode. " becomes %22

$completeurl = 'http://somesite.com/?param1=' . urlencode(trim($param)) . '...';

See also:

Upvotes: 2

Related Questions