Forum Moderators: coopster

Message Too Old, No Replies

HTML Special Characters

Special Characters issue and PHP

         

tabish

4:43 pm on Jan 4, 2007 (gmt 0)

10+ Year Member



hello,

How to deal if someone enters something like this in textarea field?

♡♥♡♥♡♥♡♥♡♥
♡♥♡♥♡♥♡♥♡♥
♡♥♡♥♡♥♡♥♡♥
♡♥♡♥♡♥ ╔╦╦Θ
╦╦╦Θ╦╦╦Θ╦╦
╦Θ╦╦╗╔╦╦Θ╦
╦╦Θ╦╦╦Θ╦╦╦
Θ╦╦╗ ♣ E ♣ N ♣ J ♣
O ♣ Y ♣ ╚╩╩Θ╩╩╩
Θ╩╩╩Θ╩╩╩Θ╩
╩╝╚╩╩Θ╩╩╩Θ
╩╩╩Θ╩╩╩Θ╩╩

How to remove these with PHP?

Regards
Tabish

[edited by: tedster at 6:55 pm (utc) on Jan. 4, 2007]
[edit reason] added line breaks to prevent side scroll [/edit]

rokec

5:09 pm on Jan 4, 2007 (gmt 0)

10+ Year Member



I'd recommend preg_replace();

tabish

5:12 pm on Jan 4, 2007 (gmt 0)

10+ Year Member



how to know how much these special characters are? if i know the exact number only then i can use preg()

I am confused.

regards

ahmedtheking

5:16 pm on Jan 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Lol, love it! Well, just use a expression like this:

$x = preg_replace("/&(^;)+;/","",$_POST['textfield']);

Ta da.

tabish

5:31 pm on Jan 4, 2007 (gmt 0)

10+ Year Member



LOL..

see everybody is not as smart as you ;)

thanx..
Tabish

tabish

5:58 pm on Jan 4, 2007 (gmt 0)

10+ Year Member



by the way.. it is not working

the original srting i get after using htmlspecialchars() is like this

♡♥♡

and your preg pattern is not removing it :(

regards

ahmedtheking

6:02 pm on Jan 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try $x = preg_replace("/\&(\^;)+;/","",$_POST['textfield']);

tabish

6:40 pm on Jan 4, 2007 (gmt 0)

10+ Year Member



i am using like this.. and it is not working

$text="♡♥♡♥♡♥";
$interests_value = preg_replace("/\&(\^;)+;/","",$text);
echo($interests_value);

regards

ahmedtheking

7:05 pm on Jan 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try "/[&?#?(0-9a-zA-Z)+;]+/"

tabish

8:19 am on Jan 5, 2007 (gmt 0)

10+ Year Member



Sorry..

Not working.. it is removing all the charecters which is in that text variable. Mean if there is some text like :

$text="&amp#9574;&amp#920;&amp#9574;this is text&amp#9574;&amp#9574;&amp#920;&amp#9574;this is text&amp#9574;"

It will remove that special chracters and also the text between them also..

:(
Regards
Tabish

ahmedtheking

9:35 am on Jan 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok try this

"/[(&¦#){1}(0-9a-zA-Z)+;?]/"

tabish

9:57 am on Jan 5, 2007 (gmt 0)

10+ Year Member



NOT WORKING... :(

this is what i am trying to convert

$text="♡♥♡♥ ♡♥♡♥& #9825;♥♡♥♡ ♥♡♥♡& #9829;♡♥♡♥ ♡♥♡♥& #9825;♥♡♥♡ ♥♡♥♡♥
LOVE IS MY PASSION,
LIFE IS TOO LONG SO ENJOY EVERY MOMENT,
LIVE N LET LIVE,
DONT CARE ABT D WORLD,
╔╦╦Θ╦ ╦╦Θ╦╦ ╦Θ╦╦╦ Θ╦╦╗╔ ╦╦Θ╦╦ ╦Θ╦╦╦ Θ╦╦╦Θ ╦╦╗"

I think new line is giving problem..

when i use your preg it is returning only ",,,,,"

regards
tabish

[edited by: jatar_k at 2:23 pm (utc) on Jan. 5, 2007]
[edit reason] added spaces for sidescroll [/edit]

ahmedtheking

10:21 am on Jan 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok this is getting a bit long, go and have a read of this: [uk.php.net...] and have a go yourself cos you're not going to learn with me just telling you what to try!?

henry0

12:41 pm on Jan 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Instead of trying hard to establish a removal pattern.

Your real problem is that you did not create a good enough filter to check user's input before letting the user send it to your DB.

you have two possibilities:
A) create a pattern that filters what's not allowed
B) A better one: Create a pattern that matches what's allowed (so you do not take a chance in forgetting anything)