Problems with <A href=\"http and \">

Discussion in 'PHP' started by photosales.co.nz, Jul 3, 2007.

  1. #1
    How can I strip out charactors like =\" - I want to get rid of the \ out of the code.

    I am using InnovaStudio WYSIWYG Editor and using that for formating html emails to send to subscribers.

    When I get the emails it looks like the following:

    <DIV>This is our last test of this message system, we hope that the url function is now working correctly.</DIV>
    <DIV>&nbsp;</DIV>
    <DIV><A href=\"http://www.photosales.co.nz\" target=_blank>http://www.photosales.co.nz</A></DIV>
    
    Code (markup):
    I have been trying to follow the following guide http://www.confuci.us/edit/documentation/default_start.htm with no success - I still can not get rid of those back slashes.

    Any ideas please....

    I have the following for the textarea:

    	
    <textarea name="msg" id="article" rows=4 cols=30>
    <?
    function encodeHTML($sHTML)
    {
    $sHTML=ereg_replace("&","&amp;",$sHTML);
    $sHTML=ereg_replace("<","&lt;",$sHTML);
    $sHTML=ereg_replace(">","&gt;",$sHTML);
    return $sHTML;
    }
    
    if(isset($_POST["msg"]))
    {
    $sContent=stripslashes($_POST['msg']); //Remove slashes
    echo encodeHTML($sContent);
    }
    ?>
    </textarea>
    
    Code (markup):
    Which I thought would strip the slashes out.
     
    photosales.co.nz, Jul 3, 2007 IP
  2. photosales.co.nz

    photosales.co.nz Peon

    Messages:
    371
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is there any simple way to get rid of the backslashes?
     
    photosales.co.nz, Jul 3, 2007 IP
  3. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #3
    stripslashes()
     
    ansi, Jul 3, 2007 IP
  4. glowdot

    glowdot Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    He used that already, but he may need to use it twice.

    Also, you can use htmlspecialchars to do the conversion of tags from < to &lt; etc...
     
    glowdot, Jul 3, 2007 IP
  5. photosales.co.nz

    photosales.co.nz Peon

    Messages:
    371
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sorry, bit lost there.

    Below is the file that the form is being sent to for emailing:

    <?php
    
    $db_host = $_POST['host'];
    $db_user = $_POST['username'];
    $db_pass = $_POST['password'];
    $db_name = $_POST['db'];
    $body = $_POST['msg'];
    $sub = $_POST['subject'];
    $table = $_POST['table'];
    $row = $_POST['row'];
    $from = $_POST['from'];
    $return = $_POST['return'];
    
    
     // CONNNECT TO DATABASE
    $dbDB = mysql_connect($db_host, $db_user, $db_pass) or die("ERROR: Could not connect to backend database.");  
    mysql_select_db($db_name) or die("ERROR: Could not select control database."); 
    
    // Pull emails
    $results = mysql_query("SELECT $row FROM $table") or die("Could not pull emails<br>".mysql_error());
    $sent = mysql_num_rows($results);
    
    if($row = mysql_fetch_assoc($results)) {
                    
        do {
            
            
            $email_body = $body;
            
            $subject = $sub;
            
            $email_header = "From: $from\n";
            $email_header .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal
            $email_header .= "Return-Path: <$return>\n";
            $email_header .= "Content-type: text/html; charset=iso-8859-1\r\n";
            
            mail($row["email"], $subject, $email_body, $email_header);
            
        } while ($row = mysql_fetch_assoc($results));
            
            
    } else {
        echo "No Email Addresses to send.";
    } ?> Your message has been sent<br>
    <br><?php echo(  $email_body ); ?>
    Code (markup):
     
    photosales.co.nz, Jul 3, 2007 IP
  6. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #6
    you could also str_replace("/","",$_POST['msg'])
     
    ansi, Jul 3, 2007 IP
  7. photosales.co.nz

    photosales.co.nz Peon

    Messages:
    371
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks, where would I put that bit of code?
     
    photosales.co.nz, Jul 3, 2007 IP
  8. photosales.co.nz

    photosales.co.nz Peon

    Messages:
    371
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I have found the following:

    $filtered_message = str_replace("\","",$_POST['msg']);

    But then I get the error:
    Parse error: syntax error, unexpected '"' in /home/photosal/public_html/manager/email-send.php on line 30


    Need to get rid of the \ here is some of the code that comes through the email:

    <A href=\"http://www.photosales.co.nz\">http://www.photosales.co.nz</A> </DIV>
     
    photosales.co.nz, Jul 4, 2007 IP
  9. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #9
    yeah sorry about that. you need to escape the \ so that it itself isn't escaping the "

    
    $filtered_message = str_replace("\\","",$_POST['msg']);
    
    PHP:
     
    ansi, Jul 4, 2007 IP
  10. photosales.co.nz

    photosales.co.nz Peon

    Messages:
    371
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Still got <A href=\"http://www.photosales.co.nz\">http://www.photosales.co.nz</A>

    <?php
    
    $db_host = $_POST['host'];
    $db_user = $_POST['username'];
    $db_pass = $_POST['password'];
    $db_name = $_POST['db'];
    $body = $_POST['msg'];
    $sub = $_POST['subject'];
    $table = $_POST['table'];
    $row = $_POST['row'];
    $from = $_POST['from'];
    $return = $_POST['return'];
    
     // CONNNECT TO DATABASE
    $dbDB = mysql_connect($db_host, $db_user, $db_pass) or die("ERROR: Could not connect to backend database.");  
    mysql_select_db($db_name) or die("ERROR: Could not select control database."); 
    
    // Pull emails
    $results = mysql_query("SELECT $row FROM $table") or die("Could not pull emails<br>".mysql_error());
    $sent = mysql_num_rows($results);
    
    if($row = mysql_fetch_assoc($results)) {
                    
        do {
            
            
            $email_body = $body;
            
            $subject = $sub;
    [B]$filtered_message = str_replace("\\","",$_POST['msg']);[/B]
            $email_header = "From: $from\n";
            $email_header .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal
            $email_header .= "Return-Path: <$return>\n";
            $email_header .= "Content-type: text/html; charset=iso-8859-1\r\n";
            
            mail($row["email"], $subject, $email_body, $email_header);
            
        } while ($row = mysql_fetch_assoc($results));
            
            
    } else {
        echo "No Email Addresses to send.";
    } ?> Your message has been sent<br>
    <br><?php echo(  $email_body ); ?>
    
    
    
    Code (markup):
     
    photosales.co.nz, Jul 4, 2007 IP
  11. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #11
    what's in email_body? you're setting a value in filtered_message, but i don't see you using it.
     
    ansi, Jul 4, 2007 IP
  12. photosales.co.nz

    photosales.co.nz Peon

    Messages:
    371
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #12
    The $email_body is from the contents of the wysiwyg editor - or the problem area that is doing the \ part.

    Should I be replacing the $filtered_message to $email_body?
     
    photosales.co.nz, Jul 4, 2007 IP
  13. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #13
    yeah probably. try replacing email_body with filtered_message first. if that doesn't work to the str_replace on email_body instead. assuming that both are the same thing. hard to tell.
     
    ansi, Jul 4, 2007 IP
  14. photosales.co.nz

    photosales.co.nz Peon

    Messages:
    371
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Pretty much nailed that one - thank you for your help.

    Now I just need to get outlook to be able to view the email as html.

    Thanks again
     
    photosales.co.nz, Jul 4, 2007 IP
    ansi likes this.
  15. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #15
    glad i could help bud :)
     
    ansi, Jul 4, 2007 IP
    photosales.co.nz likes this.