Forum Moderators: coopster

Message Too Old, No Replies

pound signs

safari adding extra characters to markup

         

fwordboy

3:58 pm on Oct 12, 2005 (gmt 0)

10+ Year Member



I've got a form that upload job details to a database among which is a salary field - this can be numerical or text based eg "£3000" or "good salary". On safari when I submit the form it adds an A character with a ^ above it which renders as a? on the website.

I use str_replace to convert the pound sign into

£
but I can't seem to use a str_replace to get rid of this foreign A or find our why safari adds it.

Any ideas?

dreamcatcher

6:13 pm on Oct 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi fwordboy,

Is the data coming from an array? It may be that the array was not initialised before it was used. Hence the inclusion of the strange character. I`m not sure why this happens, but I had a similar problem earlier this year.

If it is an array, make sure you initialise it first. ie:

$variable = array();

dc

fwordboy

8:51 pm on Oct 12, 2005 (gmt 0)

10+ Year Member



the data comes from
$_POST['form_field'];
so I think that's an array isn't it? ANd i upoad to the database like so

$salary = str_replace('£','£',$_POST['salary']);
and then insert the [code]$salary into the database.

dreamcatcher

9:53 am on Oct 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you post some more of your code?

fwordboy

10:59 am on Oct 13, 2005 (gmt 0)

10+ Year Member



yeah sure, I think the problem isn't Safari but the Apache server. As it seems to do it on the remote server (Linux Apache) but not on my testing server (Apple Apache).

the form:


<form id="add_job" method="post" action="/recruitment/admin/functions/jobs.php">
...
<label for="wage">Wage *</label><input type="text" id="wage" name="wage" tabindex="4" />
...
</form>

the PHP/SQL


//convert £s into escaped £ signs
$_POST['wage'] = str_replace('£', '&pound;', $_POST['wage']);

I've established that the strange character is added after the last str_replace code snippet.

dreamcatcher

11:21 am on Oct 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Might be just a case of trial and error until you get something that works. Have you tried assigning a new variable to the data like this:

$variable = str_replace('£', '&pound;', $_POST['wage']);

Then add to the database using the new variable. Or assign the data like this:

$variable = $_POST['wage'];

Then do the string replace upon database insertion:

INSERT INTO table (field) VALUES ('".str_replace("£", "&pound", $variable)."');

See if that helps.

dc

fwordboy

12:20 pm on Oct 14, 2005 (gmt 0)

10+ Year Member



thanks dreamcatcher, your first suggestion seems to have worked.

and thanks to everyone who responded to my problem.

dreamcatcher

3:32 pm on Oct 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool, glad you got lucky. :)

fwordboy

12:55 pm on Oct 17, 2005 (gmt 0)

10+ Year Member



dreamcatcher, actually when I looked back at the code today, it was still faulty but the following seems to have fixed it:


//convert £s into escaped £ signs
$wage = htmlentities($_POST['wage']);
$wage = str_replace("&Acirc;", "", $wage);