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
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!

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.