Forum Moderators: coopster
<?php [1][edited by: Simone100 at 11:16 pm (utc) on Jan. 22, 2008]
$one= "<span style='color: rgb(70,0,0)'>test1</span>";
$one[3] = "file1.txt";
$one1 = preg_grep('/(?:<span)/', $one);
$one2 = preg_grep('/(?:<span)/', $one, PREG_GREP_INVERT);
$get1 = $one1[array_rand($one1)];
$get2 = $one2[array_rand($one2)];
$get3 = file_get_contents($get2);
echo $get1;
echo $get3;
?>
<?php
$one[1] = "<span style='color: rgb(70,0,0)'>test1</span>";
$one[2] = "file1.txt";
$two1 = preg_grep('/(?:<span)/', $one);
$two2 = preg_grep('/(?:<span)/', $one, PREG_GREP_INVERT);
$rand1 = $two1[array_rand($two1)];
$rand2 = $two2[array_rand($two2)];
$file = file_get_contents($rand2);
$get = $rand1 + $file;
echo $get;
?>
.....This only brings back the word "Array" on every page load and nothing else. Is there anyway I can grab onto both? Please let me know, thank you very much.
<?php
$one[1] = "<span style='color: rgb(70,0,0)'>test1</span>";
$one[2] = "file1.txt";
$two1 = preg_grep('/(?:<span)/', $one);
$two2 = preg_grep('/(?:<span)/', $one, PREG_GREP_INVERT);
$rand1 = $two1[array_rand($two1)];
$rand2 = $two2[array_rand($two2)];
$file = file_get_contents($rand2);
$get = array_merge($rand1,$file);
echo $get;
?>
For it to choose one randomly. Problem I'm having is for the web page files file_get_contents needs to be used somewhere or the web page files aren't echo'd properly. But when I use file_get_contents
then the text isn't echo's properly. How can I include them both without getting php error messages? Please let me know, thank you very much.
$one[1] = "<span style='color: rgb(70,0,0)'>test1</span>";
$one[2] = get_file_contents("file1.txt");
$two1 = preg_grep('/(?:<span)/', $one);
$two2 = preg_grep('/(?:<span)/', $one, PREG_GREP_INVERT);
Its late so maybe I've missed something, but it looks like you are going around in circles.
. I'm trying to have the script look through everything in array $one for both span text and web page text files.
For it to choose one randomly
<?php
$one[1] = "<span style='color: rgb(70,0,0)'>test1</span>";
$one[2] = file_get_contents("file1.txt"); // returns a string of the file contents of file1.txt
$search = preg_grep('/(?:<span)/', $one); // matching pattern chosen.
$rand = array_rand($search); // will pick 1 random [b]key[/b]
echo $search[$rand];
?>
If I do this:
<?php
$one[1] = "<span style='color: rgb(70,0,0)'>test1</span>";
$one[2] = file_get_contents("file1.txt");
$search = preg_grep('/(?:<span)¦(?:txt)/', $one);
$rand = array_rand($search);
echo $search[$rand];
?>
It shows "test1" on every page load.
How do I get it to grab "file1.txt" as well?
Please let me know, thank you very much.
So you should have a 50% chance of getting either the text from $oneor $one[2]. I am assuming that you have a <span tag in the contents of file1.txt, or 'txt' in there? As that is all your regex is searching for. <edit> [1][edited by: PHP_Chimp at 7:35 pm (utc) on Jan. 24, 2008]
You could try -
<?php
$one[0] = "<span style='color: rgb(70,0,0)'>test1</span>";
$one[1] = file_get_contents("file1.txt");
$rand = array_rand($one);
$result = preg_match_all('/(<span [^\n]+)¦(txt [^\n]+)/', $one[$rand], $matches); // you may well need to alter this to get what you want.
if ($result!== false) {
echo '<pre>;
print_r($matches);
echo '</pre>';
}
else {
echo 'There was an error, please try again ;)';
}
?>