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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

???

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.