TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-12-2011, 06:48 PM   #1 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default stripslashes help

Got a small problem with a bit of code i am working on. I am reading a text file putting it to a temp file (the contents of it) then removing it to creat a fresh copy. Then i am adding the old content back and adding the new content to it also that was submited in the form, but the contents contain slashs which are messing up the page because the page reads the file and displays the contents in it.

I come out with this to strip the slashs but for some reason it wont work.

PHP Code:
//now lets pull out the tmp data (old data)
    
$ctoaddtmp file_get_contents("../DOCS/originalsLISTtmp.txt");
    
//$ctoaddorg = file_get_contents("../DOCS/originalsLIST.txt");
    //now input the old data to the file
    
$myoldfile "../DOCS/originalsLIST.txt";
    
$ctoadd3 $ctoaddtmp $displaytext;
    
stripslashes($ctoadd3);
    
$fhtmp fopen($myoldfile'w') or die("can't open file");
    
fwrite($fhtmp$ctoadd3);
    
fclose($fhtmp); 
It just does nothing, the slashes remain there and wont move, could someone please point me in the right direction! Thanks
Tim Dobson is offline  
Reply With Quote
Old 07-12-2011, 07:57 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

stripslashes is only for back slashes only to prevent quoted strings. But there is also other text replacement functions out there. my favorites are strtr and str_replace Plus in those functions you still need to save the results in a variable or they are not going to stay.

I would do it like this:
PHP Code:
//now lets pull out the tmp data (old data)
$ctoaddtmp = file_get_contents("../DOCS/originalsLISTtmp.txt");
//now input the old data to the file
$ctoadd3 = str_replace(array('/', '\\'), '', $ctoaddtmp . $displaytext);
$myoldfile = "../DOCS/originalsLIST.txt";
file_put_contents($myoldfile, $ctoadd3);
tony is offline  
Reply With Quote
The Following User Says Thank You to tony For This Useful Post:
Tim Dobson (07-13-2011)
Old 07-13-2011, 11:01 AM   #3 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

It is back slashes that are causing the problem, and although that what you put does work, i have a table in there and it is removing the close tag slash in there.

here is a bit of code of the result when i use my code just to show you.

PHP Code:
<tr><td>
<
div class=\"vid\">
<div id=\"orgdialog9\" title=\"The Dolphin song (original)\">
    <iframe title=\"YouTube video player\" class=\"youtube-player\" type=\"text/html\" width=\"560\" height=\"345\" src=\"http://www.youtube.com/embed/IM_Ru4PXb-A\" frameborder=\"0\" allowFullScreen></iframe>
</div>
<a href=\"#\" id=\"orgopener9\">The Dolphin song (original)</a></div>
</td><td>
<div class=\"vid\">
<div id=\"orgdialog10\" title=\"Thunder (original)\">
    <iframe title=\"YouTube video player\" class=\"youtube-player\" type=\"text/html\" width=\"560\" height=\"345\" src=\"http://www.youtube.com/embed/ZcmT9j-fPj8\" frameborder=\"0\" allowFullScreen></iframe>
</div>
<a href=\"#\" id=\"orgopener10\">Thunder (original)</a></div>
</td></tr><tr><td>
<div class=\"vid\">
<div id=\"orgdialog11\" title=\"Ong Bak (Original)\">
    <iframe title=\"YouTube video player\" class=\"youtube-player\" type=\"text/html\" width=\"560\" height=\"345\" src=\"http://www.youtube.com/embed/NZl7u7-nQps\" frameborder=\"0\" allowFullScreen></iframe>
</div>
<a href=\"#\" id=\"orgopener11\">Ong Bak (NEW)</a></div>
</td> 
using your code removes the slash from the </td> and </tr>
Tim Dobson is offline  
Reply With Quote
Old 07-13-2011, 12:19 PM   #4 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

Ok if it is just the back slashes that you want to get rid of, then you can use the stripslashes, like you've done. But you need to save the results of that call in a variable. Kind of like this:

PHP Code:
//now lets pull out the tmp data (old data)
$ctoaddtmp = file_get_contents("../DOCS/originalsLISTtmp.txt");
//now input the old data to the file
$ctoadd3 = stripslashes($ctoaddtmp . $displaytext);
$myoldfile = "../DOCS/originalsLIST.txt";
file_put_contents($myoldfile, $ctoadd3);
tony is offline  
Reply With Quote
The Following User Says Thank You to tony For This Useful Post:
Tim Dobson (07-13-2011)
Old 07-13-2011, 12:48 PM   #5 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

great stuff works how i need it to thanks :D
__________________
Like Music? The next best thing is here! Visit Julie Gowers website
Tim Dobson is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cleaning data before entering database question Killswitch General 7 12-24-2007 11:29 PM


All times are GMT. The time now is 11:53 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design