Jump to content

[SOLVED] include part of an array...I can't make this work


redknight

Recommended Posts

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... :o so I'm out of ideas. ty

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

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));
?>

???

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

 

 

Ok solved! ;D 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.