Stripping/Replacing Ampersand Sign

Started on the old forum in May 2009 · view the original in the archive · old links redirect here

1 reply · 392 views · started 17 years ago · 1 min read

2 participants
modfiles Developer · 200 posts #1

Hi, I'm using this snippet to strip/replace the & sign (i mostly get that error in my page if theres that sign in a string their but i dont like the result coz it shows & instead of & that wont give errors. Can anyone have a better one.

$search = array('&', '&');
$replace = array('&', '&');
$output  = & & & 
$result = str_replace($search, $replace, $output);
echo '$result';

& & & // POST RESULT No error on page

if its possible to post a result of: & & & //No error

and sometimes, in a directory list (wapbuddy) if the filename is 1_&.jpg the snippet will rename the download link as 1_&.jpg which is not valid download already and will result to file not found.

synergyx2009 Developer · 86 posts #2

when inserting into db use:

$variable_a = mysql_real_escape_string($_POST["variable"]);
$variable_b = str_replace('&', "&", $variable_a);
$variable = htmlspecialchars($variable_b);

when calling from db use:

<?php $variable = unhtmlspecialchars($item[variable]); echo "$variable"; ?>

make sure you have following in core.php

function unhtmlspecialchars( $string )
        {
        $string = str_replace ( '&', '&', $string );
        $string = str_replace ( ''', '\'', $string );
        $string = str_replace ( '"', '"', $string );
        $string = str_replace ( '<', '<', $string );
        $string = str_replace ( '>', '>', $string );
        $string = str_replace ( 'ü', '?', $string );
        $string = str_replace ( 'ä', '?', $string );
        $string = str_replace ( 'Ä', '?', $string );
        $string = str_replace ( 'ö', '?', $string );
        $string = str_replace ( 'Ö', '?', $string );
        $string = str_replace ( "\'", "'", $string );
	return $string;
        }

|Dont forget to say thanx|

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close