Help!

Status
Not open for further replies.

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
How could I do a

foreach ($links) {
$i++;
echo "$links[$i]";
$tmp = getimagesize("$links[$i]");
$ttl_size += $tmp[0];
};

this spits out an error

? ? ?
 

vudo0

New Member
Messages
13
Reaction score
0
Points
0
What kind of error?

Warning: getimagesize: Unable to open "$links[$i]" for reading. in
/home/public_html/script.php on line 12

Is the error something like that?
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
Cant remember, I usually use perl and have moved to php a few days back.

In perl you would do the loop as above but instead of $links[0] you would use $_, whereas php(just found out now) it would go like this.

foreach ($links as $_) {
$i++;
echo "$_";
$tmp = getimagesize("$_
$ttl_size += $tmp[0];
};

Thaks for the help though!
 

vudo0

New Member
Messages
13
Reaction score
0
Points
0
Did you add
PHP:
<?php
in front of the script?

Example:

PHP:
<?php
foreach ($links as $_) {
$i++;
echo "$_";
$tmp = getimagesize("$_
$ttl_size += $tmp[0];
};
<?
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
I know that much at least, sorry man.

The only thing that gets me at the moment is the similarity to perl and yet the backwardness of the way you script.

I mean in perl:
$ is a scalar,
@ is a array &
% is a hash.

In php:
$ could be a scalar/array/hash and you wouldnt know unless you set it.
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
Try this:
PHP:
foreach ($links as $value) {
echo $value;
$tmp = getimagesize($value);
$ttl_size += $tmp[0];
};
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
I just find using
PHP:
$_
much easier, this and
PHP:
@_
are standard in perl.
Is there no such thing in php?
Edit:
My next question(whilst I have some peeps attention).

In perl regex:
Substitution goes as follows:
Code:
$string = '100x100';
print $string =~ s/^[100]/10/; #would print 10x100
print $string =~ s/[100]$/10/; #would print 100x10
Grouping:
Code:
$string = '100x100';
$string =~ /(\w.+)x(\w.+)/;
print $1; # prints the words/digits up till the "x"
print $2; # prints the words/digits after the "x"

can php do this(the later is more of a concern)?

Edit:
Ok just found that there are perl compatible regular expressions in php, they just backward and not as easy to remember.
 
Last edited:

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
I don't use perl so I'm not really sure what the comparisons are. It seems you figured out your regex question though. Is this issue solved?
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
Yes, regex issuses solved, my need for help not though.
Can always open another thread when the time comes.

Close it go on, I know you want to.

P.S. Can I ask a question(not personal(Ithink))?
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
wondering why you dont have a sig?
Edit:
Also am i allowed ti have a .htaccess file?

Code:
<FilesMatch "^.*.png">SetHandler application/x-httpd-php</FilesMatch>
 
Last edited:
Status
Not open for further replies.
Top