Stripping/Replacing Ampersand Sign

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Stripping/Replacing Ampersand Sign

    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.
    Code:
    $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.
    Last edited by modfiles; 02.05.09, 10:31.

    #2
    when inserting into db use:
    Code:
    $variable_a = mysql_real_escape_string($_POST["variable"]);
    $variable_b = str_replace('&', "&", $variable_a);
    $variable = htmlspecialchars($variable_b);
    when calling from db use:
    Code:
    <?php $variable = unhtmlspecialchars($item[variable]); echo "$variable"; ?>
    make sure you have following in core.php
    Code:
    function unhtmlspecialchars( $string )
            {
            $string = str_replace ( '&amp;', '&', $string );
            $string = str_replace ( '&#039;', '\'', $string );
            $string = str_replace ( '&quot;', '"', $string );
            $string = str_replace ( '&lt;', '<', $string );
            $string = str_replace ( '&gt;', '>', $string );
            $string = str_replace ( '&uuml;', '?', $string );
            $string = str_replace ( '&auml;', '?', $string );
            $string = str_replace ( '&Auml;', '?', $string );
            $string = str_replace ( '&ouml;', '?', $string );
            $string = str_replace ( '&Ouml;', '?', $string );
            $string = str_replace ( "\'", "'", $string );
    	return $string;
            }
    sigpic

    |~~Dont forget to say thanx~~|

    Comment

    Working...
    X