Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts

    ereg_replace, doesnt work for all smileys?

    My Problem is Solved! All I needed to do was escape the ( charecter for some reason...


    Hi, i was just playing around with php (its how you learn :P)
    and I came up with this script:

    PHP Code:
    <?php
    $image 
    "http://ludatha.com/.smileys/";

    if(isset(
    $_POST['content'])){
        
    $content $_POST['content'];
        
    $content ereg_replace(":)""<img src='" $image "smiley1.gif' alt='' />"$content);
        
    $content ereg_replace(";)""<img src='" $image "smiley2.gif' alt='' />"$content);
        
    $content ereg_replace(":O""<img src='" $image "smiley3.gif' alt='' />"$content);
        
    $content ereg_replace(":o""<img src='" $image "smiley3.gif' alt='' />"$content);
        
    $content ereg_replace(":0""<img src='" $image "smiley3.gif' alt='' />"$content);
        
    $content ereg_replace(":D""<img src='" $image "smiley4.gif' alt='' />"$content);
        
    $content ereg_replace(":d""<img src='" $image "smiley4.gif' alt='' />"$content);
        
    $content ereg_replace(":S""<img src='" $image "smiley5.gif' alt='' />"$content);
        
    $content ereg_replace(":s""<img src='" $image "smiley5.gif' alt='' />"$content);
        
    $content ereg_replace(":(""<img src='" $image "smiley6.gif' alt='' />"$content); // Line 15
                
        
    $content ereg_replace("/n""<br />"$content);

        echo 
    $content;
        echo 
    "<br /><br />";
        echo 
    '<a href="ellie.php">Go Back</a>';
    }else{
        echo 
    '<form id="form1" name="form1" method="post" action="ellie.php">
      <textarea name="content" id="content" cols="45" rows="5"></textarea><br /><input name="submit" type="submit" value="Go!" />
    </form>'
    ;

    }
    ?>
    Now its simple and unsecure I know, but it doesnt work when you run it.
    It says there is an error on line 15, If you comment out line 15 the script runs...

    Why doesnt work, Help a newbie

    PHP Code:
        $content ereg_replace(":(""<img src='" $image "smiley6.gif' alt='' />"$content); // Line 15 
    I dont see any difference bewteen that and other lines above it...


    The error is:
    Warning: ereg_replace() [function.ereg-replace]: REG_EPAREN in D:\wamp\www\ellie.php on line 17
    Last edited by Ludatha; 07-29-2008 at 02:28 PM.

  • #2
    Regular Coder BWiz's Avatar
    Join Date
    Mar 2006
    Location
    Sol System
    Posts
    471
    Thanks
    7
    Thanked 21 Times in 21 Posts
    What is the error?
    BWiz :: Happy Coding!
    2006
    2007 2008 2009
    2010 2011
    Irrational numbers make no sense.

  • #3
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    Warning: ereg_replace() [function.ereg-replace]: REG_EPAREN in D:\wamp\www\ellie.php on line 15
    I should have posted that sorry :P

    EDIT: I solved the problem, I had to escape the ( charecter for some reason...
    Last edited by Ludatha; 07-29-2008 at 02:29 PM.

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    For some reason?

    It's because it is used for grouping characters together.

    Why are you still using the ereg functions anyhow? It's going down like a flaming oil tanker with the advent of PHP6. That and the PCRE functions (preg_*) are much more efficient.

    Besides, with that code the use of ereg_replace() is worthless. You're not matching any patterns, leaving with needless overhead. str_replace() would do just fine.

  • #5
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    ok since we are on the subject, how could you make the script secure? like using mysql_real_escape_string on the outcome, because it mucks it up.


  •  

    Posting Permissions

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