Page 1 of 2
Dividing a String into parts [SOLVED]
Posted: Tue Jul 25, 2006 10:40 am
by tecktalkcm0391
I am having trouble remembering how to do this:
I have PHP printing this on a page:
1 - 2 - 3 - 4 - 5
I want another PHP page to "run" that page and get the HTML it outputs along with the numbers and then divide it by the " - " and delete the " - " all together. But I want it to do this for however long the string it so if its
1 - 2 - 3 - 4 - 5 - 6 - 7 it would do it 7 times and then put it in an array and then count the array and then print some stuff on that new page.
How would I do something like that?
Thanks,
Chris
Posted: Tue Jul 25, 2006 10:45 am
by Benjamin
Posted: Tue Jul 25, 2006 10:46 am
by Burrito
look at
explode()
edit: damn it...nice job quick draw mcgraw! beat me to it!
Posted: Tue Jul 25, 2006 11:05 am
by tecktalkcm0391
ok, well how could I get the contents of numbers.php to be read by display.php to be set to a string, which is exploded.
Posted: Tue Jul 25, 2006 11:07 am
by Benjamin
Show your code yo.
Pegleg Jackson wrote:edit: damn it...nice job quick draw mcgraw! beat me to it!
Yargh..
Posted: Tue Jul 25, 2006 11:08 am
by tecktalkcm0391
Code: Select all
<?php
$str = include("../game/Florida/fantasy5.php");
// (up) outputs 3 - 17 - 22 - 26 - 32 or what ever numbers they change every so often
$numbers = array();
$numbers = explode(' - ', $str, -1);
print_r($numbers);
?>
Posted: Tue Jul 25, 2006 11:14 am
by Benjamin
I was hoping your code would give me a better idea of what your trying to do, but here goes..
Code: Select all
$numbers = explode(' - ', $str, -1);
$numbers = implode('.', $numbers);
echo '<a href="page.php?values="' . $numbers . '">ARG</a>';
and then in page.php
Code: Select all
$numbers = explode('.', $_GET['values']);
Posted: Tue Jul 25, 2006 11:18 am
by tecktalkcm0391
OK, well here is a better idea of what I am trying to do.. I have a script that is outputting numbers.... the a format of X - X - X - X - X and I want to extract each of the numbers by somehow getting the numbers from the page that generates them (numbers.php, which users never see or go to) putting them into a string on (page.php, which is what the users see) and then printing them for a parameter for a flash animation in the following.
Code: Select all
<param name="flashvars" value="num1=(NUMBER 1)&num2=(NUMBER 2)&num3=(NUMBER 3)&num4=(NUMBER 4)&num5=(NUMBER 5)">
Posted: Tue Jul 25, 2006 11:28 am
by Benjamin
untested..
Code: Select all
$numbers = explode('.', $_GET['values'])
$counter = 1;
$queryString = '?';
foreach ($numbers as $value)
{
$queryString .= 'num' . $counter . '=' . $value . '&';
$counter++;
}
$queryString = substr($queryString, 0, -1);
$paramString = '<param name="flashvars" value="' . $queryString . '">';
astions is
closed till tomorrow.. gotta get some sleep

Posted: Tue Jul 25, 2006 2:38 pm
by tecktalkcm0391
Well could someone tell me how to "read" another file and get its contents.
Posted: Tue Jul 25, 2006 2:51 pm
by feyd
a logical
file_get_contents()... come on now, you aren't doing research anymore?
Posted: Tue Jul 25, 2006 3:04 pm
by tecktalkcm0391
Sorry. I've been doing the research I even found that, but I keep getting stuff that is wrong. At one time I was getting the PHP codes from the page in the source code.
Posted: Tue Jul 25, 2006 3:07 pm
by tecktalkcm0391
How would I do that anyways, if I do it like this:
Code: Select all
$sFile = file_get_contents("home/dir/numbers.php");
if($sFile==FALSE){
print 'error';
}
print $sFile;
I get the PHP Codes in the source, and nothing on the page.
If I do
Code: Select all
$sFile = file_get_contents("http://site.com/dir/numbers.php");
if($sFile==FALSE){
print 'error';
}
print $sFile;
I get
Warning: file_get_contents(
http://site.com/dir/numbers.phphp) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in /home/test.php on line 3
error
Posted: Tue Jul 25, 2006 3:34 pm
by feyd
you want the code to run?
include() it.
Posted: Tue Jul 25, 2006 7:32 pm
by tecktalkcm0391
I want the code to run and then for its outputed info to be put to a variable I can use on a page of PHP.