Page 2 of 2

Posted: Fri Nov 03, 2006 11:04 am
by RobertGonzalez

Code: Select all

<?php
$array[0] = 'http://www.wmdirectory.com/category-9-0.htm';
$array[1] = 'http://www.altavista.com/';
$array[2] = 'http://www.wmdirectory.com/deadlink-1035.htm';
$array[3] = 'http://www.wmdirectory.com/category-39-0.htm';
$array[4] = 'http://www.wmdirectory.com/category-84-0.htm';
$array[5] = 'http://www.wmdirectory.com/category-38-0.htm';
$array[6] = 'http://www.wmdirectory.com/deadlink-353.htm';
$array[7] = 'http://www.wmdirectory.com/info-1035.htm';
$array[8] = 'http://www.google.com';
$array[9] = 'http://www.yahoo.com'; 


$find_this_domain = 'wmdirectory.com';
$limit_finds = 2;
$counter = 0;

foreach ($array as $value)
{
	if (stristr($value, $find_this_domain))
	{
		$newarray[$counter] = $value;
		$counter++;
		
		if ($counter == $limit_finds)
		{
			break;
		}
	}
}

echo '<pre>';
print_r($newarray);
echo '</pre>';
?>

Posted: Fri Nov 03, 2006 9:57 pm
by olddog
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


[quote="pgolovko"]Hmmm, I'm a bit confused. How would I apply the above code into "while" loop here?

Code: Select all

if (mysql_num_rows($result) <> ''){
  while ($row = mysql_fetch_array($result)) {

    if(strlen($row['title']) > 100){ $row['title'] = substr($row['title'], 0, 100)."..."; }
    if(strlen($row['description']) > 500){ $row['description'] = substr($row['description'], 0, 500)."..."; }
    $results[] = $row;
    }
  }
[/quote]

Code: Select all

// CREATE AN EMPTY CONTAINER
$my_container = array();

// TEST SUCCESS
if (mysql_num_rows($result))
{ 
	// LOOP 
	while ($row = mysql_fetch_array($result))
	{ 
		// MEASURE THIS FIRST-- REDUCE TO INTEGER MATH
		$tmax = strlen($row['title']);
		$dmax = strlen($row['description']);
		
		// NOW TEST IT
		$row['title']		= ($tmax<100)?$row['title']			:substr($row['title'], 0, 97)."...";
		$row['description']	= ($dmax<500)?$row['description']	:substr($row['description'], 0, 497)."...";
		
		// NOW SAVE IT
		$my_container[] = $row;
	
	} 
}
// YOU NEED TO COMMENT YOUR CODE

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]