Re: php: assignment operator
| From: | Analysis & Solutions | Date: | Wed, 07 Aug 2002 00:41:45 +0000 |
| Subject: | Re: php: assignment operator | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111458@lists.php.net to get a copy of this message | ||
On Tue, Aug 06, 2002 at 07:54:47PM -0500, Anthony Ritter wrote:
>
> for($i=0; $i<strlen($counter); $i++)
> {
> $image_src=$image_dir. "/" .substr($counter, $i, 1) . ".jpg";
> $image_tag_src.="<IMG SRC=\"$image_src\" BORDER=\"0\">";
> // assignment
> operator .=
> }
See http://www.php.net/manual/en/language.operators.assignment.php.
.= appends the text to the right of the operator to the end of the
variable on the left side of the operator.
Therefore, $image_tag_src will be one long string containing several "<img
src..." in it, one for each time the loop executes.
Be careful. Before using this operator, make sure you manually set the
variable to something, such as:
$image_tag_src = '';
before starting in order to avoid people hacking your code by putting
nasty text in the $image_tag_src variable.
> If I was to assign the html string to the variable $image_tag_src without
> the .= and insert a =, the script continues to run fine since $image_src
> still contiunes to hold the value of
> $image_dir. "/" .substr($counter, $i, 1) . ".jpg";
That's the case if strlen($counter) is 1. If it were more, you'd see
multiple image tags in there.
--Dan
--
PHP classes that make web design easier
SQL Solution | Layout Solution | Form Solution
sqlsolution.info | layoutsolution.info | formsolution.info
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409