Big help needed cant figure ...

They have: 18 posts

Joined: Feb 2005

$query = "SELECT `wrd` FROM `tf` WHERE `wrd` LIKE 'e6' LIMIT 0 , 1";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$menu .= "$row[word]";
}

$page_data = file_get_contents('/"$menu"');
preg_match($page_data, $array);
$array = explode(', ', $array);
echo "$array[0]";

Really could use some direction here - the query and the file_get_contents work scripts work BUT only seperately.

I need them to work together .. for dynamics.

Busy's picture

He has: 6,151 posts

Joined: May 2001

remove the limit 0,1

They have: 18 posts

Joined: Feb 2005

I may have a turn in the right direction

not sure why feeding a result from a query to a seperate php script wont be accepted..
what I have so far...

$query = "SELECT `wrd` FROM `tf` LIMIT 0,1";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$menu .= "$row[word]"; }

$pagedata = file_get_contents("/srch/$menu");
This would not work at all "$menu" a result from query just will not be parsed.

The only way the query & the php parse within "file_get_contents" is like this...
$trial .= file_get_contents("http://domain.com/srch/$menu"); \\ I had to add the dot part
see now "$trial" is um Im not sure???

not closer to finishing the script because the next two lines are the magic.

The page which Im calling "http://domain.com/srch/$menu" is only some text
where Im stripping text between some quotes.

Im not sure if "$trial" is now an array and these 2 lines are now the wrong method.

$pattern = '/new (([^)]+)?)/';
preg_match($pattern, $trial, $array);

The array var.. after this pattern match will be stored and seperated into results

echo "$array[0], $array[1], $array[3]";

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

What is that pattern trying to find?

file_get_contents(); is like readfile(); except it doesn't just print the text, or like file(); but file breaks the file into an array based on the NewLine.

do a print_r($array) at the end, and show us the results.

They have: 18 posts

Joined: Feb 2005

The result has this template
dn(frame, "qwe", new Ar("asd", "zxc"), new Ar(""), new Ar(""));

("asd", "zxc") // NOTE: this is the array area, exclude the rest

----------------------
code to put into array

$trial = str_replace('dn(', '', $trial);
$trial = str_replace(');', '', $trial);
$pattern = '/new Ar(([^)]+)?)/';
preg_match($pattern, $trial, $array);
$array = str_replace('"', '', $array[1]);
$array = explode(', ', $array);
$array = str_replace ("(", "", $array);

result needed:

row[0] - row[1] - row[2]

#########
Update on the query code:

$result = mysql_query("SELECT * FROM `ut8` LIMIT $srt , $amn") or exit(mysql_error());
while ($row = mysql_fetch_assoc($result)) {$word[] = $row['word'];}
$menua .= "$word[0]";
$menub .= "$word[1]";

$trial .= file_get_contents("http://domain.com/feed/$menua");

#########
area of problem
adding a period before ".="
otherwise "$menua" is not being parsed.

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

<?
$trial = "dn(frame, \"qwe\", new Ar(\"asd\", \"zxc\"), new Ar(\"\"), new Ar(\"\"));";
preg_match_all('/(new Ar)+\(+([A-z\", ])+\)/',$trial,$matches);
$trial = $matches[0];
$trial = str_replace(array("new Ar(",")","\"",";"),'',$trial);
while(list($k,$v) = each($trial)){
if($v == ""){
unset($trial[$k]);
}
}
print_r($trial);
?>

returns:
Array
(
    [0] => asd, zxc
)
'

They have: 18 posts

Joined: Feb 2005

OOPS my mistake

new Ar("asd", "zxc")
this is not a static result asd, zxc change dependant on $menua

sorry

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

That doesn't matter, the script will still find other variables.

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

<?
$trial = "dn(frame, \"qwe\", new Ar(\"adfadfadsfsd\", \"zfadsfadfxc\", \"fdkasfjkasf\"), new Ar(\"dsafdsf\",\"dasfadsf\"), new Ar(\"\"));";
preg_match_all('/(new Ar)+\(+([A-z\", ])+\)/',$trial,$matches);
$trial = $matches[0];
$trial = str_replace(array("new Ar(",")","\"",";"),'',$trial);
while(list($k,$v) = each($trial)){
if($v == ""){
unset($trial[$k]);
}
}
print_r($trial);
?>
returns:
Array
(
    [0] => adfadfadsfsd, zfadsfadfxc, fdkasfjkasf
    [1] => dsafdsf,dasfadsf
)
'

as long as the bits between the "" in the Ar("") only contain letters, numbers, or spaces, you're all good.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.