473,769 Members | 6,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reversing str_replace() function in the textbox.

3 New Member
I am developing my form into a captcha secured form and I used header() function if the user didn't put the verification code properly and still when the user go back to the form page the filled he have filled have still remained. In addition, users are usually submitting multiliner texts in the textbox so I used the str_replace() function to make all \n into %n% to prevent an error in the header function whenever the form is submitted. my script is:

Expand|Select|Wrap|Line Numbers
  1. // load the variables form address bar
  2. $category = $_REQUEST["jokecategory"];
  3. $title = $_REQUEST["joketitle"];
  4. $verif_box = $_REQUEST["verif_box"];
  5. $text = $_REQUEST["joke"];
  6.  
  7. // remove the backslashes that normally appears when entering " or '
  8. $MyTitle = addslashes($_POST[title1]);
  9. $MyText = addslashes($_POST[text1]);
  10.  
  11. $text = str_replace("\n", '%n%', $text);
  12.  
  13. // check to see if verificaton code was correct
  14. if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
  15.  
  16.     $q1 = "insert into dd_items set 
  17.  
  18.                     ItemTitle = '$MyTitle',
  19.  
  20.                     ItemCategory = '$MyCategory',
  21.  
  22.                     ItemSubcategory = '$MySubcategory',
  23.  
  24.                     ItemText = '$MyIn|$MyText',
  25.  
  26.                     Contributor = '$_SESSION[username]',
  27.  
  28.                     DateAdded = '$t' ";
  29.  
  30.  
  31.  
  32.     mysql_query($q1) or die(mysql_error());
  33.  
  34.  
  35.  
  36.     header("location:test.php");
  37.  
  38.     exit();
  39.  
  40. } else {
  41.     // if verification code was incorrect then return to contact page and show error
  42.     $text = str_replace("%n%", '\n', $text);
  43.     header("Location:".$_SERVER['HTTP_REFERER']."?jokecategory=$category&joketitle=$title&joke=$text&wrong_code=true");
  44.  
  45.     exit;
  46. }
  47.  
Now problem is that, I don't know where or how to reverse $text = str_replace("\n ", '%n%', $text); function in the textbox so whenever the user entered a wrong verification code the \n will not appear neither the %n%, it will be automatically put in the next line inside the textbox. Any ideas? Please see the bolded lines, it is where I put the functions and tried to reverse it yet if was a failure.
Jul 31 '07 #1
4 3072
code green
1,726 Recognized Expert Top Contributor
PHP does not recognise \n within single quotes.
It needs to be within double quotes. "\n"
But instead of converting backwards and forwards why not store the original?
Also, by re-arranging your logic you could improve your efficiency more.
Jul 31 '07 #2
d1srupt3r
3 New Member
What do you mean store the original? You mean I don't have to use the str_replace()? If that so, I will have an error "Warning: Header may not contain more than a single header, new line detected." if the form is submitted because the user may have entered more than one line in the textbox. That is why the solution I thought is to replace every "\n" into "%n" so that the server will not confused of the new lines. I said earlier I used the header() function. About re-arranging the logic, the script I posted is stripped just to make it simple to show my problem. :]

To see what I am doing, please click here . If the people entered more than one line in the textbox and able to provide the correct verification number, there's no problem at all but if the user entered a wrong verification number and has more that one line in the textbox, the "\n" actually in the textbox instead to make a new line.
I hope this makes clearer about my problem. :)
Jul 31 '07 #3
code green
1,726 Recognized Expert Top Contributor
What do you mean store the original?
[PHP]$origText = $text;
$text = str_replace("\n ", '%n%', $text);[/PHP]
You mean I don't have to use the str_replace()?
Not twice no.
I am sorry but you lose me after this but the idea is you use $origtext with the error and $text when OK;
Jul 31 '07 #4
d1srupt3r
3 New Member
I found the solution now! Wooohoo! What I did was to put this codes inside the textarea:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $text = $_GET['joke'];
  3. $text = str_replace("%n%", "\n", $text);
  4. echo "$text";
  5. ?>
  6.  
Thanks for the help guys! ^^
Jul 31 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
21559
by: Hugo Coolens | last post by:
I need to use the str_replace function for a php-script which works together with html/javascript. In the script I have to perform things like: $arabic=str_replace ("'","\'", $row); $arabic=str_replace ("sh", "\š", $row); the second line works perfectly, however I can't make the first one work, it should replace a single quote with a quote preceded by a backslash. I presume I have to escape some characters to make this happen however...
2
1563
by: barry | last post by:
I am using the following code in a textbox: Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged Dim txt As TextBox = CType(sender, TextBox) txt.Text = txt.Text.ToUpper End Sub
11
8094
by: Tim Marshall | last post by:
I use Terry Kreft's & Stephen Lebans colour dialog procedures for users to pick colours for various control properties in certain apps. Is there a way to take the colour code that is displayed in a backcolor/forecolor/etc property and calculate the "reverse colour"? In other words, If a user picks 255 (red) for a control backcolor, I'd like to be able to calculate the opposite or negative of that colour and assign the control's...
1
1678
by: marcomputers | last post by:
Hi, I'm trying to automatically update an existing rss podcast file using php and the str_replace function. Every time I add a media file, it should read the .rss file into a string, take the closing </channel> and </rss> tags out of it, and add the new rss file info to the end of the existing string, writing it back to the rss file. However, str_replace will not replace the </channel> and </rss> tags with ' '. I'm new to php, any help...
2
1597
by: Brad Everman | last post by:
Something simple, perhaps someone can shed some light. I have an array of paragraphs of text and am replacing some of the text using str_replace(). Ex. function addGraphic($numGraphic){ return("this is graphic $numGraphic");
2
1124
by: kencana | last post by:
Hi all, I got a doubt about the str_replace function. <?php $string="avenue 1, ave 1"; $words=str_replace ("ave","avenue", $string); echo $words; ?>
8
4762
by: arnuld | last post by:
i have created a solutions myself. it compiles without any trouble and runs but it prints some strange characters. i am not able to find where is the trouble. --------------------------------- PROGRAMME -------------------------------- /* K&R2 section 1.9 exercise 1.19
3
6101
by: steezli | last post by:
Hi, Brand new to VB.NET and I'm having a problem figuring out this program. I'll try and be descritive as possible. I have to create a Windows application that contains a single top-level form with two textboxes on it, on positioned above the other. As each character is entered into the upper textbox, the string that has been entered into the upper textbox must appear in the lower textbox, but in reverse. If the input field contains...
3
2193
by: jodleren | last post by:
Hi all I have text area, where I can edit files - but I have to correct the returned data, for that I use $content=str_replace('\"', '"', $content); and $content=str_replace('\\', '\', $content); by some reason the latter one causes an error: syntax error,
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.