Web Analytics Made Easy -
StatCounter I need help with preg_match - CodingForum

Announcement

Collapse
No announcement yet.

I need help with preg_match

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I need help with preg_match

    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.

    ه = å
    ن = ä
    ِ = ö

  • #2
    You mean these are entered into a text input and provided to PHP? Then yes, you can use htmlentities to convert these.
    PHP Code:
    $str 'ه ن ِ';

    print 
    htmlentities($strENT_COMPAT'UTF-8'); 
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

    Comment


    • #3
      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 ?

      Thanks in advise.

      Comment


      • #4
        Originally posted by Haidar View Post
        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 ?

        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.
        PHP Code:
        header('HTTP/1.1 420 Enhance Your Calm'); 
        Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

        Comment


        • #5
          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 dosnنt have to be an hard sample, just an easy html test-page so i can see where the code should stick and so.

          Comment


          • #6
            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:
            PHP Code:
            $str 'ه ن ِ';
            $entities htmlentities($strENT_COMPAT'UTF-8');

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

            Results in a simple:
            Code:
            <div>
                <p>The following are special characters: &aring; &auml; &ouml;</p>
            </div>
            PHP Code:
            header('HTTP/1.1 420 Enhance Your Calm'); 
            Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

            Comment

            Working...
            X