Jump to content

[SOLVED] Apostrophes and <br>


shamuraq

Recommended Posts

I have a mix of both <br> and apostrophes in my multiline form entry that i need to send to MySQL BLOB. When i searched online i found that i can use str_replace(). When i tried coding it i realise i can only use it only for either <br> or apostrophe not both.

 

I tried using mysql_real_escape_string() but nothing was sent to database.

Below is my current stable script only replacing <br> with "/n". How do i add apostrophe string replace?

//$challenge=$_POST['challenge'];
$challenge = str_replace("\n","<br>",$_POST['challenge']);
//$solutions=$_POST['solutions'];
$solutions = str_replace("\n","<br>",$_POST['solutions']);
//$remarks=$_POST['remarks'];
$remarks = str_replace("\n","<br>",$_POST['remarks']);

 

Thanx in advance...

Link to comment
Share on other sites

$challenge = str_replace("'","\'",nl2br($_POST['challenge']));

That should fix you up.

Jons, can you explain a bit to me the breakdown of your code? Because when i call it back from MySQL i need to replace it back to its original form...

 

Link to comment
Share on other sites

sure.

str_replace("'", "\'", $_POST['challenge'])

I'm sure you know what that does: it changes ' to \'

Next: nl2br() is the short code for changing new lines to <br />

I just made the code smaller by doing it all in one line.

so, when you pull it out of the database, you just do this:

<?php
//db connection
//db query
//results
//lets assume you put your results into array $row, and the column that has challenge is called "challenge"
$challenge = str_replace("\'","'", $row['challenge']); // if you want to remove the <br />, do it this way:str_replace("\'","'", str_replace("<br />, "\n", $row['challenge']);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.