Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:31:06+00:00 2026-06-04T02:31:06+00:00

Having a problem with single quote/apostophes in some php I am writing to parse

  • 0

Having a problem with single quote/apostophes in some php I am writing to parse smilies.

The single quote is the bane of my life, but here goes.

First here’s some of the code…

First my array which holds the smiley and the filename of that smiley.

This is a separate file (smiley-map.php).

<?php 
$smilies = array (
array('code' => ':)', 'filename' => 'smiley.gif'),
array('code' => ':(', 'filename' => 'sad.gif'),
array('code' => ';)', 'filename' => 'wink.gif'),
array('code' => ':D', 'filename' => 'grin.gif'),
array('code' => ';D', 'filename' => 'cheesy.gif'),
array('code' => '>:-(', 'filename' => 'angry.gif'),
array('code' => ':O', 'filename' => 'shocked.gif'),
array('code' => '8)', 'filename' => 'cool.gif'),
array('code' => '???', 'filename' => 'huh.gif'),
array('code' => '::-)', 'filename' => 'rolleyes.gif'),
array('code' => ':P', 'filename' => 'tongue.gif'),
array('code' => ':-[', 'filename' => 'embarrassed.gif'),
array('code' => ':*', 'filename' => 'lipsrsealed.gif'),
array('code' => ':-/', 'filename' => 'undecided.gif'),
array('code' => ':x', 'filename' => 'kiss.gif'),
array('code' => ':\'(', 'filename' => 'cry.gif'),
array('code' => '>:-D', 'filename' => 'evil.gif'),
array('code' => '^-^', 'filename' => 'azn.gif'),
array('code' => 'O0', 'filename' => 'afro.gif'),
array('code' => 'LOL', 'filename' => '2funny.gif'),
array('code' => ':bash:', 'filename' => 'knuppel2.gif'),
array('code' => '>_<', 'filename' => 'tickedoff.gif'),
array('code' => ':?', 'filename' => 'idiot.gif'),
array('code' => ':!', 'filename' => 'uglystupid.gif'),
);
?>

Then I parse them in a simple manner like this :

 <?php
 function parseSmilies($string)
 {
require_once("smilies/smiley-map.php");

for ($i = 0; $i < count($smilies); $i++)
{
    $filename = '<img src="smilies/' . $smilies[$i]['filename'] . '" alt="smiley" title="' . $smilies[$i]['code'] . '" />';
    $string = str_replace($smilies[$i]['code'], $filename, $string);
}
return $string;
 }
 ?>

So it goes…include smile map…array now available…search string for codes…swap code for image tag.

This all works fine on my local machine (XAMPP). But when I upload and run it in myserver, it misses the cry one :'(

I imagine this is the single quote causing a probelm, despite my having escaped it in the array..

Presumably there is some PHP setting that is affecting this ?

Could anyone advise please ?

Many thanks.

EDIT: $string originates from $_POST

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:31:07+00:00Added an answer on June 4, 2026 at 2:31 am

    This probably has something to do with Magic Quotes.
    When Magic Quotes are turned on in your PHP server, the ' in all superglobals ($_GET, $_POST etc.) gets replaced with \' and " gets replaced with \". This mechanism has been deprecated as of PHP 5.3.0 and removed as of PHP 5.4.0.

    However, most web-hosting servers do not even have PHP 5.3.0 yet, while private servers like XAMPP are likely to have a more recent version of PHP. So your localhost probably will not have Magic Quotes turned on while your webserver will.

    Magic Quotes makes it impossible to perform SQL injection when including a superglobal value directly into the query. For example:

    <?php
    
    $query = 'SELECT id FROM users WHERE name = "' . $_POST['name'] . '" AND password = "' . $_POST['password'] . "'";
    
    ?>
    

    Someone entering a 1" OR "1" = "1 in the password field could easily change the query into SELECT id FROM users WHERE name = "admin" AND password = "1" OR "1" = "1" effectively logging in on the administrator account without knowing the password.


    That said, I think Magic Quotes was only a fallback mechanism for people not securing their input and you should always turn it off. It’s a better practice to secure your own application instead of letting PHP do it.

    Disabling Magic Quotes

    This can be done using php.ini but I suppose you don’t have access to that file on a hosted server. The following snippet emulates disabling Magic Quotes:

    <?php
    
    if( get_magic_quotes_gcp( ) )
    {
        function stripslashes_deep( $val )
        {
            return is_array( $val ) ? array_map( 'stripslashes_deep', $val )
                                    : stripslashes( $val );
        }
        
        $_GET     = stripslashes_deep( $_GET );
        $_POST    = stripslashes_deep( $_POST );
        $_COOKIE  = stripslashes_deep( $_COOKIE );
        $_REQUEST = stripslashes_deep( $_REQUEST );
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problem with escaping the single and double quotes inside the href
I'm having quite a weird problem here. I have just pasted the Yii folder
I'm trying to convert some MYSQL querys to MYSQLI, but I'm having an issue,
Maybe I'm just thinking about this too hard, but I'm having a problem figuring
I'm using powershell v1.0 and having a problem terminating a 'here string', the console
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
I'm having problem when running my Windows Forms program. In the program, I have
I'm having problem with Rails plugin attachment_fu . On every upload, I get validation
i'm having problem to deal with charset in ruby on rails app, specificially in
I am having problem in getting reference of Ajax control extender using $find() or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.