Jump to content

Need looping and array help


liquidmind

Recommended Posts

Here is a quick  graphic display of what I want code to do.

preg_match.jpg

 

Right now what the code is doing is giving me the correct preg_matches results for the last item in the list only. If I have one item in the list it will give me the results for that one item. If the list is two items then it will give me the correct results for item 2 while showing null results (0) for 1. If the list is three items, it will give me the results for item 3 while showing null results for 1 and 2...etc. Null results = 0 as directed by $count_matches=0; in code.

 

Please ignore the following lines: ("xxxx" is just in place of actual code I don't want to display).

$link="xxxx"

preg_match "xxxx"

 

<?
if (!isset($_POST['itemlist'])) 
{
?>

<form name="form" method="post">
<textarea rows=5 cols=20 name="itemlist" value="<?=$_POST['itemlist']?>" </textarea>
<input type="submit" name="formsubmit" value="Submit!" class="button_style"><br />
</form>

<?
} 

else {


$itemlist = explode("\n",$_POST['itemlist']);
$count = 0;
foreach ($itemlist AS $item) {

$ab=curl_init();

$link="xxxx"

curl_setopt($ab,CURLOPT_URL,$link);
curl_setopt($ab, CURLOPT_HEADER, 0);

ob_start();
curl_exec($ab);
curl_close($ab);
$item_results=ob_get_contents();
ob_end_clean();

preg_match "xxxx"

$count_matches=$match[1];

if($count_matches=="")
$count_matches=0;

echo "<br/>".$item." ".$count_matches."";

$count++;
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/99450-need-looping-and-array-help/
Share on other sites

Here is a quick  graphic display of what I want code to do.

preg_match.jpg

 

Right now what the code is doing is giving me the correct preg_matches results for the last item in the list only. If I have one item in the list it will give me the results for that one item. If the list is two items then it will give me the correct results for item 2 while showing null results (0) for 1. If the list is three items, it will give me the results for item 3 while showing null results for 1 and 2...etc. Null results = 0 as directed by $count_matches=0; in code.

 

Please ignore the following lines: ("xxxx" is just in place of actual code I don't want to display).

$link="xxxx"

preg_match "xxxx"

 

<?
if (!isset($_POST['itemlist'])) 
{
?>

<form name="form" method="post">
<textarea rows=5 cols=20 name="itemlist" value="<?=$_POST['itemlist']?>" </textarea>
<input type="submit" name="formsubmit" value="Submit!" class="button_style"><br />
</form>

<?
} 

else {


$itemlist = explode("\n",$_POST['itemlist']);
$count = 0;
foreach ($itemlist AS $item) {

$ab=curl_init();

$link="xxxx"

curl_setopt($ab,CURLOPT_URL,$link);
curl_setopt($ab, CURLOPT_HEADER, 0);

ob_start();
curl_exec($ab);
curl_close($ab);
$item_results=ob_get_contents();
ob_end_clean();

preg_match "xxxx"

$count_matches=$match[1];

if($count_matches=="")
$count_matches=0;

echo "<br/>".$item." ".$count_matches."";

$count++;
}
}
?>

 

I'm not going to look through all your code, fix it and if it still doesn't work come back. I see several spots that are missing semi-colons.

 

preg_match "xxxx"

That's not even correct.

 

$link="xxxx"

Not correct

 

Replace with

$link="xxxx";

 

<textarea rows=5 cols=20 name="itemlist" value="<?=$_POST['itemlist']?>" </textarea>

Not correct.

 

Replace:

<textarea rows=5 cols=20 name="itemlist" value="<?=$_POST['itemlist'];?>" </textarea>

 

etc. etc. Go through your code!

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.