Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Str_replace On Submitted Text 1

Status
Not open for further replies.

bacterozoid

Technical User
Nov 22, 2005
2
US
I have a textbox that I will be submitting info into. All my info comes from users on MS-Word. I need to run a str_replace on the info I paste from word in the box to replace all instances of single and double quotes, as well as the combined dash MS-Word makes when you use two dashes.

This is from a Cutenews script (I've tried their forum...but it's not very good for this type of problem).

// Save The News Article In Active_News_File

$all_db = file("$decide_news_file");

foreach($all_db as $news_line){
$news_arr = explode("|", $news_line);
if($news_arr[0] == $added_time){ $added_time++; }
}

$news_file = fopen("$decide_news_file", "w");

fwrite($news_file, "$added_time|$member_db[2]|$title|$short_story|$full_story|$manual_avatar|$category||\n");
foreach ($all_db as $line){ fwrite($news_file, "$line");}
fclose($news_file);

That just opens a news.txt file and writes a bunch of set variables into it. I figure that maybe this is where I am supposed to run the str_replace.

Any ideas?

Thanks
 
According to what the form is set to you will find the data in $_GET (<form name="foo" method="get"...) or in $_POST for posted data. These arrays are superglobals that are associative arrays which are keyed by the name attributed of the input fields.

For replacing you can use str_replace with arrays that contain the characters to be replaced and the replacement chars. The PHP documentation is a good starting point: Here's an example:
Code:
<?php
$badChars = array('a','b','"');
$goodChard = array ('z','y','');
$cleanSubject = str_replace($badChars, $goodChars, $subject);
?>
 
Ok...I get what you're saying there...but it's not that simple to use arrays, is it? That str_replace doesn't replace each variable in the array; it'll just do the first one, if any at all, because there are multiple values in the array - correct?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top