Converting & to %26 using htmlspecialchars in the following function

54 Views Asked by At

I'm unable to get my head around this one.

As per the following, if Author name = Simon&Schuster, then it'll add simon&schuster to the URL. Problem is the & character is also part of the search function so putting it in the URL screws things up. How can I convert the following so that & character is displayed normally on the page, but in the URL it is written as simon%26schuster?

$authors = explode("\r\n", $value );

$value = '';
foreach ($authors as $au){
    $elements = ((strpos($au, ",") === false) ? array(0 => $au) : (explode(",", $au)));
    $index = 0;
    foreach ($elements as $element) {
        $value .= (($index++ === 0) ? '' : ', ') . '<a href="authors.php?q=(Author~contains~'. $element . ')">'. $element . '</a>';
    }
}
0

There are 0 best solutions below