cola Posted February 11, 2009 Share Posted February 11, 2009 Hello i have problem with inserting content of file. My code is: <?php $l="www.something.net"; $cg = file_get_contents($l); $cg = strip_tags($cg); $cg = mysql_real_escape_string($cg); $cg = str_replace ('\n',' ', $cg; $cg = str_replace ('\t',' ', $cg); $cg = str_replace ('\0',' ', $cg); $cg = str_replace ('\xOB',' ', $cg); mysql_query("INSERT INTO table (content) VALUES ('$cg');") ; ?> This is work but problem is that i get lot of squars i think that they represent some blank space in pages but i can not remove them. for exammple i get in mysql: square squre some text square sguare square squre some text. I have more squres then text i need to remove theme Can someone help me? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/144757-solved-inerting-content-of-file-in-database/ Share on other sites More sharing options...
printf Posted February 11, 2009 Share Posted February 11, 2009 Change the parameter(s) in your str_replace(s) to use double quotes * "\n" *, as single quotes * '\n' * are no parsed (they do not interpolate) Quote Link to comment https://forums.phpfreaks.com/topic/144757-solved-inerting-content-of-file-in-database/#findComment-759592 Share on other sites More sharing options...
cola Posted February 11, 2009 Author Share Posted February 11, 2009 Thank you for replay this is solve my problem but now other thing do not work. I want to strip all between <script></script> tags but my code do not work well. This code goes before strip_tags preg_match_all('/<script(.*)<\/script>/i', $cg, $script); foreach ($script[1] as $s) { $cg = str_replace ($s,' ', $cg); } This is sript all content of website and i get empty sting in the database. I want to strip only text between these tags. Page have lot of script tags. Quote Link to comment https://forums.phpfreaks.com/topic/144757-solved-inerting-content-of-file-in-database/#findComment-759690 Share on other sites More sharing options...
premiso Posted February 11, 2009 Share Posted February 11, 2009 Why not use preg_replace instead of str_replace As I do not think str_replace allows for regex...and for something "that" complicated, it would be better to use the preg function instead. Quote Link to comment https://forums.phpfreaks.com/topic/144757-solved-inerting-content-of-file-in-database/#findComment-759703 Share on other sites More sharing options...
cola Posted February 11, 2009 Author Share Posted February 11, 2009 Thank you, I get same results with preg_replace and string_replace. can anyone help me to solve problem with script tags? Quote Link to comment https://forums.phpfreaks.com/topic/144757-solved-inerting-content-of-file-in-database/#findComment-759734 Share on other sites More sharing options...
premiso Posted February 11, 2009 Share Posted February 11, 2009 <?php $string = "test <script>tasetsetasetst</script> test2"; $string = preg_replace('/<script(.*)<\/script>/i', '', $string); echo $string; die(); ?> Works fine for me. Quote Link to comment https://forums.phpfreaks.com/topic/144757-solved-inerting-content-of-file-in-database/#findComment-759737 Share on other sites More sharing options...
cola Posted February 11, 2009 Author Share Posted February 11, 2009 This is work when you have one script tags. But if u have more then do not. For example <?php $string = "test <script>tasetsetasetst</script> test2<script>tasetsetasetst</script>"; $string = preg_replace('/<script(.*)<\/script>/i', '', $string); echo $string; die(); ?> result of this will be test, i want to get test test2 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/144757-solved-inerting-content-of-file-in-database/#findComment-759760 Share on other sites More sharing options...
premiso Posted February 11, 2009 Share Posted February 11, 2009 <?php $string = "test <script>tasetsetasetst</script> test2<script>tasetsetasetst</script>"; $string = preg_replace('%<script(.+?)<\/script>%is', '', $string); echo $string; die(); ?> Try that. Word between tabs topic for more in-depth information on regex. Quote Link to comment https://forums.phpfreaks.com/topic/144757-solved-inerting-content-of-file-in-database/#findComment-759775 Share on other sites More sharing options...
cola Posted February 11, 2009 Author Share Posted February 11, 2009 Thank you, This is what i need Quote Link to comment https://forums.phpfreaks.com/topic/144757-solved-inerting-content-of-file-in-database/#findComment-759787 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.