Jump to content

Recommended Posts

hello everyone. i am having a problem sending semi colons, commers etc through an ajax page using php.  when the text is displayed on the page i am getting squares and other symbols instead.  i have had this problem before and i am pretty sure a fixed it with adding and stripping slashes from the text as it was sent but cannot for the life of me find the fixed version of this code.

 

any help on this would be great.  here is the section from the php

 

<?php

$cOption = $_GET['o'];

switch($cOption) {
	case 1:
		echo "<h1>who we are</h1><br />
        Welcome to our site here at design-flow Liverpool.  We are a web design company that pride ourselves in producing functional and user friendly websites.  We take great care in making sure that the websites we produce fit the needs of the client and the people who will be using the website on a regular basis.  When we take on a website, we not only take on the responsibility to produce a website that is functional but we also feel it is our duty to try and understand the wishes of the client.  In order for this to take place the client’s role in the site’s development is integral: from start to finish we will involve the client.<p>

To do this, we must first build a good understanding of our client’s needs and wishes for the site.  The way to facilitate this is by meeting with the client face to face to nurture a good relationship.";

		break;

 

 

Link to comment
https://forums.phpfreaks.com/topic/197733-stripslashes-and-addslashes/
Share on other sites

here is what is being shown from the the above variable when being displayed on the html page

 

Welcome to our site here at design-flow Liverpool. We are a web design company that pride ourselves in producing functional and user friendly websites. We take great care in making sure that the websites we produce fit the needs of the client and the people who will be using the website on a regular basis. When we take on a website, we not only take on the responsibility to produce a website that is functional but we also feel it is our duty to try and understand the wishes of the client. In order for this to take place the client�s role in the site�s development is integral: from start to finish we will involve the client.

To do this, we must first build a good understanding of our client�s needs and wishes for the site. The way to facilitate this is by meeting with the client face to face to nurture a good relationship.[/Quote]

 

The problem is that those are not straight-quotes, i.e. " or ' and escaping or not escaping has no affect on them. See this link for more information on different kinds of quotes in electronic documents - http://en.wikipedia.org/wiki/Quotation_mark_glyphs

 

I'm going to guess that this text was copy/pasted from a word processor?

 

You can either correct the text to use straight-quotes or you need to setup the character encoding on the page to a specific encoding that has the ability to display the type of quotes being used.

i have set up a ajax page to load the content froma php page on to my html pages.  it works fine but it will not show the semicolons properly i am getting symbols instead.

 

i have had this working correctly before but i have lost the code that was working and now i am stuck.  i am pretty sure i sorted it by adding and stripping the slashes but i am not 100% on this.

 

here is a copy of the php page which holds all the information

 

<?php

$cOption = $_GET['o'];

switch($cOption) {
	case 1:
		echo "<h1>who we are</h1><br />
        Welcome to our site here at design-flow Liverpool.  We are a web design company that pride ourselves in producing functional and user friendly websites.  We take great care in making sure that the websites we produce fit the needs of the client and the people who will be using the website on a regular basis.  When we take on a website, we not only take on the responsibility to produce a website that is functional but we also feel it is our duty to try and understand the wishes of the client.  In order for this to take place the client’s role in the site’s development is integral: from start to finish we will involve the client.<p>

To do this, we must first build a good understanding of our client’s needs and wishes for the site.  The way to facilitate this is by meeting with the client face to face to nurture a good relationship.";

		break;
	case 2:
		echo "<h1>why choose us</h1><br />
        The reason to choose design-flow to build your company’s website is quite simple.  All sites we build encompass the client’s passion for their company and here at design-flow we involve the client as much as possible.  We believe for the website to truly reflect the wishes of the client, they must be involved in every step of the way from the initial design to the end product.<p>
It is easy to build a site with no involvement from clients but the end product may not always be as pleasing to the client as it is to the designer.  Every step of the way the client’s thoughts and ideas are treated with the upmost respect and are incorporated into the site as much as possible.<p>
Even the Content Management Systems (CMS) we build are all individually designed so that even the back end of the site works according to the client’s wishes.  The reason we do this is that every website built will be different.  Our view here at design-flow is that all CMSs built need to be custom-made for the individual.  Another advantage of building the CMSs is that they will be end-user friendly with only the features requested available for use and no added extra components, superfluous and liable to create complications in the future.
";

		break;
	case 3:
		echo "<h1>what we offer</h1><br />
        Of course we offer basic websites and additionally we can build bespoke Content Management Systems according to the exact needs of the client.  As we know at design-flow, everybody’s site is different and will need updating in different ways.  This is why we do not build one Content Management System and try to convince the client this is what they need.  We will find out what specific needs the system has and build it to the exact required specification.  In doing this the client will always have the complete control over what the website is displaying and how it will be updated.  We also offer ecommerce sites so that our clients are able to sell products directly online.";

		break;
	case 4:
		echo "<h1>New Businesses</h1><br />
        Welcome to our site here at design-flow Liverpool.  We are a web design company that pride ourselves in producing functional and user friendly websites.  We take great care in making sure that the websites we produce fit the needs of the client and the people who will be using the website on a regular basis.  When we take on a website, we not only take on the responsibility to produce a website that is functional but we also feel it is our duty to try and understand the wishes of the client.  In order for this to take place the client’s role in the site’s development is integral: from start to finish we will involve the client.<p>

To do this, we must first build a good understanding of our client’s needs and wishes for the site.  The way to facilitate this is by meeting with the client face to face to nurture a good relationship.";

		break;
}
?>

 

 

Yes that should note. Just remember to nullify glyphs of quotes, as the one you've used was higher than 8-bits (The probable encoding). Thus it'll read as "E2 80 99" in bytes, and that is not correct, thus the replacement character (�)

i will attempt to explain myself better.

 

i have a web page which is using ajax to display the content of the pages within a div tag.  the code is all working fine the content for each of the individual links are displaying in the div tag but if the text being sent to the html page contains semicolons, commers, inverted commers etc they display as symbols.  the content is being taken from a php page which uses a case statement to select which section of the information is needed to be displayed.

 

the code from the php page can be seen above. the links on the html page look as follows

 

<a href="javascript:loadContent(1);">Home</a>[/Quote]

 

and the function used to identify which case statement to select looks like this

 

<script src="jquery-latest.js" type="text/javascript"></script>

<script type="text/javascript">

function loadContent(id) {

$("#contentArea").load("rpc.php?o="+id+"");

}

 

</script>

[/Quote]

 

there is also the javascript page which handles the xmlhttprequests but i no i do not have to change this so there is no need to post this up here

  $("#contentArea").load("rpc.php?o="+id+"");

 

What you have stated, Such as inverted commas and smarty quotes (What you have) cannot be passed through the url (Without intervension).

 

Are you aware of what Unicode is? Basically those fancy quotes take up more bytes than otherwise normal characters, that is why it appears as a "weird symbol", because the browser does not know what those extra bytes are.

 

You'll need to make EVERY single special character into HTML entities.  htmlentities can handle conversion to entities.

 

Note that many characters such as "&" should be converted into entities. Once all non-ASCII characters are converted, it can safely be sent to the url and be displayed clientside.

thanks for the reply i understood that one better.

 

from my reading htmlspecialchars() does basically the same htmlentities() but quicker.  this bit i know but what i am stuck on is where i should be using it.  i know i have state that the variable $cOption has htmlspaecialchars init and to get them to display i thought i would have to write it like this but it does not seem to be working for me

 

$cOption = htmlspecialchars($_GET['o']);

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.