peaforabrain
-
Posts
10 -
Joined
-
Last visited
Never
Posts posted by peaforabrain
-
-
Anyways, the foreach loop will never get to the end each time since you've commented out the if statement around the continue structure. I.e. this:
Sorry about that, I was just editing it afetr trying something else, and just pasted it in, without checking what i'd done.
Anyway thanks for the help. I will try that function, but I can't see it working.
-
function justify($text, $width, $break) { $marker = "__$%@random#$()__"; // lines is an array of lines containing the word-wrapped text $wrapped = wordwrap($text, $width, $marker); $lines = explode($marker, $wrapped); $result = ""; foreach ($lines as $line_index=>$line) { $line = trim($line); $words = explode(" ", $line); $words = array_map("trim", $words); $wordcount = count($words); //$wordlength = strlen(implode("/([^\s]{6})/","$1 ",$words) $wordlength = strlen(implode("", $words)); // if (3*$wordlength < 2*$width) { // don't touch lines shorter than 2/3 * width // continue; // } $spaces = $width - $wordlength; $index = 0; do { $words[$index] = $words[$index] . " "; $index = ($index + 1) % ($wordcount - 1); $spaces--; } while ($spaces>0); $lines[$line_index] = implode("", $words); } return implode($break, $lines); }
-
I've been stuck on a problem to limit text in a css cell. I would like it to be 29 characters wide and 3 lines high only (this last bit is the problem).
I have tried many of the examples on the php.net site, and none do the trick. I have also tried modifying them.
I wondered whether it is possible to acheive this?
-
I know what you mean, and it is a lot easier to just extract from one list as mentioned by toonmariner.
But I have a special need for this particular function and I actually do have it working (after a fashion because its random in its operation, not displaying the numbers as it should) using a lot of if else commands.
If you can supply me with any poiters that would be great.
thanks -
$a is defined from a function;
[
The other array is gathered from this;
-
Thanks, sorry for not being specific enough.
The number I refer to is the amount of elements that are associated to a given field as extracted from the mysql db
[quote] $count=$OneCount['name'];
$num=$OneCount['num'];
$arr2[]="$count";
$arr3[]="$num";[/quote]
I havn't really shown it in this script as I could not get it to work, but I am presuming that making the number "$arr3" loop, then it should work. -
Thanks Jenk,
Here is where I am up to.
[code=php:0] $f = htmlspecialchars($f);
$arr1[]= "$f";
}
}
{
if (!empty($a))
while(list(,$OneCount)=each($a))
{
$count=$OneCount['name'];
$num=$OneCount['num'];
$arr2[]="$count";
$arr3[]="$num";
}
{
$result = array_merge($arr1, $arr2);
$f = array_unique($result);
while (list($indexValue, $fi) = each ($f))
foreach($fi as $key => $val)
{
echo "<option $sel value=\"".htmlentities($val)."\">".htmlentities($key).'. '.htmlentities($val)."";
}[/code]
Could you point me in the direction of getting the number into the array?
Thanks again.
-
Thanks for the reply, but I have read a lot about arrays, and have tried various things.
[quote] $result = array_merge($arr1, $arr2);
$f = array_unique($result);
while (list($indexValue, $fi) = each ($f))
echo"<option $sel value=\"".$fi."\">".$fi."";[/quote]
This stops the duplication of elemnts, but I need to put the number next to the appropriate listing. -
Hi,
I wonder if anyone could help me with this;
I have two arrays, Array 1 is a list from A to Z, Array 2 is list of elements that contain data for a specific letter with a number indicating the amount of. So if 'C' for instance has two amounts of data and 'E' has one, then the list will show;
A
B
C (2)
D
E (1)
etc.
I cannot get this to work correctly, please someone help.
Word Wrap function problem
in PHP Coding Help
Posted
This may seem a bit thick, but how do I reference this function;
I have never come accross that before.