Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2003
    Location
    USA, FL
    Posts
    251

    Regular Expression Problem (PHP)

    I am trying to make a regular expression that allows about anything except <> so people cant type in html. I want to allow [] tho so i can make bbcode.

    The one i have done is below

    PHP Code:
    //[0-9a-zA-Z]+[0-9a-zA-Z:,\(\)\'\.\?\$\"\r\n[:space:]-]+$ 
    Everytime i added in\[\] it would error out.

    Any help would be greatly appreicated.

  2. #2
    if you are sing PHP a simpler and less resource intensive solution would be:

    Code:
    <?php
    $text = str_replace("<", "&lt;", $text);
    $text = str_replace(">", "&gt;", $text);
    ?>

  3. #3
    Join Date
    Mar 2003
    Posts
    878
    IIRC.. check out this function htmlspeacialchars()

  4. #4
    Join Date
    Jan 2003
    Location
    USA, FL
    Posts
    251
    I dont want ppl typing in html at all... Meaning i dont even want it converted so i was trying to make it so you couldnt even put it in unless u used my custom bbcode. Thats why i was lookin for a regular expression that could find it.

    Thanks both of u for your thoughts.

  5. #5
    Join Date
    Jan 2003
    Location
    USA, FL
    Posts
    251
    I finally just took decided to not do a regular expression and just my own custom function

    PHP Code:
    $badchar_array = array('<','>');

    for(
    $a=0;$a<count($badchar_array);$a++)
    {
        if(
    strpos($pagecode$badchar_array[$a]))
        {
            
    $errors '<li>Illegal Characters within Code';
            break;
        }

    I hope if someone else has this problem this might can help them out...

  6. #6
    Join Date
    May 2005
    Location
    Roanoke, VA
    Posts
    36
    I believe you want strip_tags().
    You cooin' with my bird?

  7. #7
    Join Date
    Jan 2003
    Posts
    82
    Well, the regexp is extremely easy if you do it the other way round

    PHP Code:
    if(preg_match('|[<>]|',$search)) {
      echo 
    "ERROR, NOT ALLOWED";


  8. #8
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    1,082

  9. #9
    Join Date
    Jan 2003
    Location
    USA, FL
    Posts
    251
    Alright thanx for the thought...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •