redknight Posted May 27, 2009 Share Posted May 27, 2009 I working on a script to filter out bad words. I have filter.php with this content ,"spam1","spam2","spam3" And I have the part of the code in which I want to include filter.php $filter = "/home/internet/domains/personal/public_html/filter.php"; $list1 = array("test".file_get_contents($filter)); $list2 = array("","","",""); I don't get an error, but it's also not working as the bad words are still showing. And it's working when I copy and paste the content of filter.php in that same spot. ??? I wat to get this code as result: $filter = "/home/internet/domains/personal/public_html/filter.php"; $list1 = array("test","spam1","spam2","spam3"); $list2 = array("","","",""); I'm have worked on this for more than an hour... so I'm out of ideas. ty Quote Link to comment Share on other sites More sharing options...
rohithreddyk Posted May 27, 2009 Share Posted May 27, 2009 what is $xfilter Quote Link to comment Share on other sites More sharing options...
rohithreddyk Posted May 27, 2009 Share Posted May 27, 2009 nevermind...wrong post from my part Quote Link to comment Share on other sites More sharing options...
redknight Posted May 27, 2009 Author Share Posted May 27, 2009 nevermind...wrong post from my part I have modified that part as it was a mistake Still looking for a solution! Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 27, 2009 Share Posted May 27, 2009 you dont use file_get_contents for a internal page ? $_SERVER['PHP_SELF'] or $_SERVER['REQUEST_URI'] Quote Link to comment Share on other sites More sharing options...
rohithreddyk Posted May 27, 2009 Share Posted May 27, 2009 I guess the whole file is being treated as one element in the array.. i mean your $list => array(test,"spam1","spam2,"spam3") which is being treated as one element. try echo $list[0] and $list[1] Quote Link to comment Share on other sites More sharing options...
rohithreddyk Posted May 27, 2009 Share Posted May 27, 2009 yes i tried your code and I am pretty sure all the file contents is being treated as one element of the array... Quote Link to comment Share on other sites More sharing options...
redknight Posted May 27, 2009 Author Share Posted May 27, 2009 you dont use file_get_contents for a internal page ? $_SERVER['PHP_SELF'] or $_SERVER['REQUEST_URI'] Ty. I don't know if you mean $list1 = array("test".$_SERVER['/home/internet/domains/personal/public_html/filter.php']); $list2 = array("","","",""); No error, but it's also not working Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 27, 2009 Share Posted May 27, 2009 to add a page that got code and wanted to be used via another page you use include("name.php"); not what your doing it all weird. Quote Link to comment Share on other sites More sharing options...
redknight Posted May 27, 2009 Author Share Posted May 27, 2009 I guess the whole file is being treated as one element in the array.. i mean your $list => array(test,"spam1","spam2,"spam3") which is being treated as one element. try echo $list[0] and $list[1] The normal way would be: <?php $list1 = array("test","spam1","spam2","spam3"); $list2 = array("","","",""); $replace = str_replace($list1, $list2, file_get_contents($page)); ?> So you mean something like <?php $filter = "/home/internet/domains/personal/public_html/filter.php"; $list1 = array("test".file_get_contents($filter)); $list2 = array("","","",""); $replace = str_replace($list1[0], $list2[1], file_get_contents($page)); ?> ??? Quote Link to comment Share on other sites More sharing options...
redknight Posted May 27, 2009 Author Share Posted May 27, 2009 to add a page that got code and wanted to be used via another page you use include("name.php"); not what your doing it all weird. I tried include, but that makes the content visible on the page. But I try again with include...ty Quote Link to comment Share on other sites More sharing options...
rohithreddyk Posted May 27, 2009 Share Posted May 27, 2009 No.. I mean the way you used $link=array("test".file-get...) is making PHP to treat your whole file as one element..because file_get_contents returns whole file as one string.. i tried echo $link[0]; echo $link[1]; i got this on the browser.. test,"spam1","spma2" Notice: Undefined offset: 1 in ..... so $link[0] printed whole file and $link[1] was not there...... when you have $link=array("test","spam1","spam2") echo $link[0]; echo $link[1]; you will get testspam1 as the output.... so im guessing you may need to parse the file for each and every word and add it to array Quote Link to comment Share on other sites More sharing options...
redknight Posted May 27, 2009 Author Share Posted May 27, 2009 Now I understand what you mean. I will start working on this Ty and I will let you know if I have it working Quote Link to comment Share on other sites More sharing options...
redknight Posted May 27, 2009 Author Share Posted May 27, 2009 Ok solved! I made for every word a different file (filter1.php, filter2.php,...) and I used this code to include the seperated files $list1 = array("test","".file_get_contents("/home/internet/domains/personal/public_html/filter1.php")."","".file_get_contents("/home/internet/domains/personal/public_html/filter2.php").""; $list2 = array("","",""); Ty all (especially rohithreddyk) for helping me out! gr. Quote Link to comment 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.