...

View Full Version : I need help with preg_match



Haidar
08-30-2011, 10:06 PM
Hey!

I have an form on my website that i would to change three letters to html-format instead of the swedish letters. Is that possible? It should be very simple only sanitazing or changing those letter into another expression, when the form is submitted.

The letter is = and here what i want them to change to.

= å
= ä
= ö

Fou-Lu
08-30-2011, 10:26 PM
You mean these are entered into a text input and provided to PHP? Then yes, you can use htmlentities to convert these.


$str = ' ';

print htmlentities($str, ENT_COMPAT, 'UTF-8');

Haidar
08-31-2011, 12:41 AM
Yes exactly. But sorry im really newbie at php, should there not be a section when the code starts?

something like: <? CODE ?>

And will this make that changes into an &aring;? How can it recognize wich form it should make the changes for? And should it be in the head section :D?

Thanks in advise.

Fou-Lu
08-31-2011, 02:20 PM
Yes exactly. But sorry im really newbie at php, should there not be a section when the code starts?

something like: <? CODE ?>

And will this make that changes into an &aring;? How can it recognize wich form it should make the changes for? And should it be in the head section :D?

Thanks in advise.

It goes wherever you want to print it out. The $str is simply the source, if it comes from a post field you can find it in a $_POST offset.

Haidar
08-31-2011, 08:33 PM
Excuse me but it would be REALLY nice if you could show me this in some sample of a html page. I would really really persiut that, so i know the strucutre. It dosnt have to be an hard sample, just an easy html test-page so i can see where the code should stick and so.

Fou-Lu
08-31-2011, 09:04 PM
Writing an HTML page will have no benefit as you cannot see the processing code.
All that matters is that how you print it out is wrapped in entities:


$str = ' ';
$entities = htmlentities($str, ENT_COMPAT, 'UTF-8');

print "
<div>
<p>The following are special characters: $entities</p>
</div>
";

Results in a simple:


<div>
<p>The following are special characters: &aring; &auml; &ouml;</p>
</div>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum