1

I need to replicate the method of converting   >   into   > Â.

I have a constant defined which is used as the separator between a child and parent category.

define('CATEGORY_SEPERATOR', '  >  ') // (constant may vary)

$sql .= "GROUP_CONCAT(c.name ORDER BY c.level SEPARATOR "'" . CATEGORY_SEPERATOR ."'") AS name

A possible result could be

row = array( 'name => category1  >  category2 )

The categories are then displayed as a list of links

<li><a href="www.example.com/categories?&name=<?php echo $row['name'];?>"><?php echo $row['name'];?></a></li>

when a link is clicked the URLS are encoded.

addressbar: `www.example.com/categories?name=category1  >  category2

I want to be able to check whether the CATEGORY_SEPERATOR exists within $_GET['name'] . so I can perform

$name = $_GET['name'];
$categories = explode(CATEGORY_SEPERATOR, $name);

but by the time $_GET['name'] reaches my script its beet transformed.

$_GET['name'] initial value

var_dump : string 'category1Â Â >Â Â category2' (length=27)

After stripslashes() (no change)

var_dump : string 'category1Â Â >Â Â category2' (length=27)

After htmlspecialchars($data, ENT_COMPAT, 'UTF-8');

var_dump : string 'category1Â Â &gt;Â Â category2' (length=30)

Now i've managed to reverse it slightly by doing the following

$_GET['name'] = htmlspecialchars_decode($_GET['name'], ENT_COMPAT);

if(ini_get('magic_quotes_gpc')){ $_GET['name'] = addcslashes($_GET['name']); }

But still need to get it from

category1Â Â >Â Â category2 to &nbsp;&nbsp;&gt;&nbsp;&nbsp;

Ive tried using urldeocde and rawurldecode, without any luck.

TarranJones
  • 4,084
  • 2
  • 38
  • 55
  • 1
    You're complaining about the `Â `? That's a character set issue. Your text is corrupted, and you'll need to fix it all - there's no 100% reliable method to detect what really SHOULD be `Â` and what's a mangled charcter. Read this: http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Marc B Nov 06 '15 at 14:37
  • Thanks, I thought that some how `Â ` was an encoded version of ` `. thanks for the link – TarranJones Nov 06 '15 at 15:50
  • ` ` is a non-breaking space. it'd never show up as `Â`, since it's by definition a space character. – Marc B Nov 06 '15 at 17:34

1 Answers1

0

Reversing the process used to encode will work but unfortunately somewhere on the client side(browser) the data is being changed/corrupted before it is sent to the server.

These are a list of the functions with there counterpart.

TarranJones
  • 4,084
  • 2
  • 38
  • 55