php-general Digest 2 Jun 2011 02:53:52 -0000 Issue 7339

Topics (messages 313292 through 313306):

Re: displaying a pdf
        313292 by: Jim Giner
        313296 by: Tamara Temple
        313298 by: Ashley Sheridan

building a key value pair dynamically
        313293 by: Adam Preece
        313294 by: jean-baptiste verrey
        313295 by: Adam Preece
        313297 by: Tamara Temple

notices nightmare - looking for a regex solution
        313299 by: Merlin Morgenstern
        313300 by: Govinda
        313301 by: Matt Giddings
        313302 by: Matt Giddings
        313303 by: Adam Richardson

Re:hello!
        313304 by: bob pilly

PHP 5.3.3 operator & problem
        313305 by: 李白|字一日
        313306 by: Simon J Welsh

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Well - the code works just fine as is and that's all I care about.  As for 
Richard's comments - the url in my header(Location....) statement points to 
a pdf file, not a php file, so the target is not sending any headers (that I 
know of ). 



--- End Message ---
--- Begin Message ---

On Jun 1, 2011, at 9:54 AM, Jim Giner wrote:

Well - the code works just fine as is and that's all I care about. As for Richard's comments - the url in my header(Location....) statement points to a pdf file, not a php file, so the target is not sending any headers (that I
know of ).

The server will send the appropriate headers for files like that. If you want to see it, try doing a wget or curl and make sure to snag the headers as well (or instead) of the actual file.

For instance:

  curl -O -D headers.txt 
'http://wiki.tamaratemple.com/uploads/Main/CoolWebThings/bumping_locks.pdf'

returns headers.txt:

HTTP/1.1 200 OK
Date: Wed, 01 Jun 2011 18:28:28 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Mon, 03 Dec 2007 02:54:08 GMT
ETag: "9386f8-323dc0-e4df9400"
Accept-Ranges: bytes
Content-Length: 3292608
Content-Type: application/pdf

without doing anything special.

(no, i don't advocate going around picking locks. it's just useful info to have...)
--- End Message ---
--- Begin Message ---
On Wed, 2011-06-01 at 13:31 -0500, Tamara Temple wrote:

> On Jun 1, 2011, at 9:54 AM, Jim Giner wrote:
> 
> > Well - the code works just fine as is and that's all I care about.   
> > As for
> > Richard's comments - the url in my header(Location....) statement  
> > points to
> > a pdf file, not a php file, so the target is not sending any headers  
> > (that I
> > know of ).
> 
> The server will send the appropriate headers for files like that. If  
> you want to see it, try doing a wget or curl and make sure to snag the  
> headers as well (or instead) of the actual file.
> 
> For instance:
> 
>    curl -O -D headers.txt 
> 'http://wiki.tamaratemple.com/uploads/Main/CoolWebThings/bumping_locks.pdf'
> 
> returns headers.txt:
> 
> HTTP/1.1 200 OK
> Date: Wed, 01 Jun 2011 18:28:28 GMT
> Server: Apache/2.2.3 (CentOS)
> Last-Modified: Mon, 03 Dec 2007 02:54:08 GMT
> ETag: "9386f8-323dc0-e4df9400"
> Accept-Ranges: bytes
> Content-Length: 3292608
> Content-Type: application/pdf
> 
> without doing anything special.
> 
> (no, i don't advocate going around picking locks. it's just useful  
> info to have...)
> 


The advantage to having PHP send the correct headers, is that the file
you are linking to does not need to be in a web accessible area, meaning
that it's protected from someone accessing it without passing some form
of security you have in place in your PHP code. Also, it removes any
issues with a server not having been set up correctly, which is quite
often a problem on IIS (Apache is a lot better, but even it has issues
with some less-popular formats)

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
hi all,

is it possible to dynamically build a key value pair array in php from a 
database result?

if so how?

kind regards

Adam

--- End Message ---
--- Begin Message ---
with mysql use mysql_fetch_assoc, is that what you are asking for ?

On 1 June 2011 16:31, Adam Preece <[email protected]> wrote:

> hi all,
>
> is it possible to dynamically build a key value pair array in php from a
> database result?
>
> if so how?
>
> kind regards
>
> Adam
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
sorry i should of explained a little more in depth :-).

i am using smarty templating engine,

and it needs me to pass in an associative array.

only an id column and a the name column.

i know if i use a more specific query, but if i have the result set already 
could i build the array so it suits the template function?

this is the function details:

http://www.smarty.net/docsv2/en/language.function.html.options.tpl

and this is the array im currently fetching.

Array ( [0] => Array ( [id] => 2 [0] => 2 [name] => category 1 [1] => category 
1 [main_nav] => true [2] => true ) [1] => Array ( [id] => 3 [0] => 3 [name] => 
category 2 [1] => category 2 [main_nav] => true [2] => true ) [2] => Array ( 
[id] => 4 [0] => 4 [name] => category 3 [1] => category 3 [main_nav] => true 
[2] => true ) [3] => Array ( [id] => 5 [0] => 5 [name] => category 4 [1] => 
category 4 [main_nav] => true [2] => true ) [4] => Array ( [id] => 6 [0] => 6 
[name] => category 5 [1] => category 5 [main_nav] => true [2] => true ) [5] => 
Array ( [id] => 7 [0] => 7 [name] => category 6 [1] => category 6 [main_nav] => 
false [2] => false ) [6] => Array ( [id] => 8 [0] => 8 [name] => category 7 [1] 
=> category 7 [main_nav] => false [2] => false ) [7] => Array ( [id] => 9 [0] 
=> 9 [name] => category 8 [1] => category 8 [main_nav] => false [2] => false ) 
[8] => Array ( [id] => 10 [0] => 10 [name] => category 9 [1] => category 9 
[main_nav] => false [2] => false ) [9] => Array ( [id] => 11 [0] => 11 [name] 
=> category 10 [1] => category 10 [main_nav] => false [2] => false ) ) Array ( 
[0] => 2=>category 1 [1] => 3=>category 2 [2] => 4=>category 3 [3] => 
5=>category 4 [4] => 6=>category 5 [5] => 7=>category 6 [6] => 8=>category 7 
[7] => 9=>category 8 [8] => 10=>category 9 [9] => 11=>category 10 

hope this makes sense?

kind regards


Adam

On 1 Jun 2011, at 16:33, jean-baptiste verrey wrote:

> with mysql use mysql_fetch_assoc, is that what you are asking for ?
> 
> On 1 June 2011 16:31, Adam Preece <[email protected]> wrote:
> hi all,
> 
> is it possible to dynamically build a key value pair array in php from a 
> database result?
> 
> if so how?
> 
> kind regards
> 
> Adam
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


--- End Message ---
--- Begin Message ---

On Jun 1, 2011, at 10:40 AM, Adam Preece wrote:

sorry i should of explained a little more in depth :-).

i am using smarty templating engine,

and it needs me to pass in an associative array.

only an id column and a the name column.

i know if i use a more specific query, but if i have the result set already could i build the array so it suits the template function?

this is the function details:

http://www.smarty.net/docsv2/en/language.function.html.options.tpl

and this is the array im currently fetching.

Array ( [0] => Array ( [id] => 2 [0] => 2 [name] => category 1 [1] => category 1 [main_nav] => true [2] => true ) [1] => Array ( [id] => 3 [0] => 3 [name] => category 2 [1] => category 2 [main_nav] => true [2] => true ) [2] => Array ( [id] => 4 [0] => 4 [name] => category 3 [1] => category 3 [main_nav] => true [2] => true ) [3] => Array ( [id] => 5 [0] => 5 [name] => category 4 [1] => category 4 [main_nav] => true [2] => true ) [4] => Array ( [id] => 6 [0] => 6 [name] => category 5 [1] => category 5 [main_nav] => true [2] => true ) [5] => Array ( [id] => 7 [0] => 7 [name] => category 6 [1] => category 6 [main_nav] => false [2] => false ) [6] => Array ( [id] => 8 [0] => 8 [name] => category 7 [1] => category 7 [main_nav] => false [2] => false ) [7] => Array ( [id] => 9 [0] => 9 [name] => category 8 [1] => category 8 [main_nav] => false [2] => false ) [8] => Array ( [id] => 10 [0] => 10 [name] => category 9 [1] => category 9 [main_nav] => false [2] => false ) [9] => Array ( [id] => 11 [0] => 11 [name] => category 10 [1] => category 10 [main_nav] => false [2] => false ) ) Array ( [0] => 2=>category 1 [1] => 3=>category 2 [2] => 4=>category 3 [3] => 5=>category 4 [4] => 6=>category 5 [5] => 7=>category 6 [6] => 8=>category 7 [7] => 9=>category 8 [8] => 10=>category 9 [9] => 11=>category 10

hope this makes sense?

This seems pretty straight-forward.

$options = array();

foreach ($rows as $row) {
        $options[]=list($row['id']=>$row['name']);
}

but then maybe i'm not understanding something...


--- End Message ---
--- Begin Message ---
Hi there,

I am working on a pretty huge site with thousands of files with php code. Unfortunatelly the app throws a ton of notices du to missing '' in arrays. Of course I could simply disable the output on the dev server to surpress notices, but I would rather like to get it fixed.

Has somebody a good idea on how to fix this automated somehow with regex?

The vars are right now: $var[element] and should be $var['element']

I was looking into sed, but I was hoping that there is also a way in php. Has anybody a hint on how to get the regex done?

I appreciate any help on that.

Best regards,

Merlin

--- End Message ---
--- Begin Message ---
> I am working on a pretty huge site with thousands of files with php code. 
> Unfortunatelly the app throws a ton of notices du to missing '' in arrays. Of 
> course I could simply disable the output on the dev server to surpress 
> notices, but I would rather like to get it fixed.
> 
> Has somebody a good idea on how to fix this automated somehow with regex?
> 
> The vars are right now: $var[element] and should be $var['element']
> 
> I was looking into sed, but I was hoping that there is also a way in php. Has 
> anybody a hint on how to get the regex done?
> 
> I appreciate any help on that.


Hi Merlin

I don't know what is sed, (and perhaps this is what you meant by that), but a 
good text editor could do the job in one decent regex, global replace.  Seems 
like asking PHP to do it is the same task, plus the added code (hassle) to walk 
all your directories for affected files.

- Govinda

--- End Message ---
--- Begin Message ---
You can put an @  symbol in front each item that is throwing the error.
That may take some time though.  You could use something like

find /htdocs_folder -name \*.php -print | xargs sed -i
s/\$array_name/@$array_name/g

That might get you what you're looking for.  But be cautious because this
method does not create a backup file for you.   You can do a quick check
(but not fool proof) by using this command

find /htdocs_folder -name \*.php -print | xargs grep "\$array_name" | more

You may need to remove the slash in front of the $ sign.

Matt

On Wed, Jun 1, 2011 at 6:26 PM, Merlin Morgenstern <[email protected]>wrote:

> Hi there,
>
> I am working on a pretty huge site with thousands of files with php code.
> Unfortunatelly the app throws a ton of notices du to missing '' in arrays.
> Of course I could simply disable the output on the dev server to surpress
> notices, but I would rather like to get it fixed.
>
> Has somebody a good idea on how to fix this automated somehow with regex?
>
> The vars are right now: $var[element] and should be $var['element']
>
> I was looking into sed, but I was hoping that there is also a way in php.
> Has anybody a hint on how to get the regex done?
>
> I appreciate any help on that.
>
> Best regards,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
I was thinking about this a little more and thought that the method I sent
before will work, but it has the potential of clobbering variables that are
not related to this warning/notice.  Best bet would be to create a list of
file names that contain the offending variables then feed that to sed using
cat file_name | sed...  You can use the find | xargs grep method to create
the initial list, then work from there.

On Wed, Jun 1, 2011 at 6:26 PM, Merlin Morgenstern <[email protected]>wrote:

> Hi there,
>
> I am working on a pretty huge site with thousands of files with php code.
> Unfortunatelly the app throws a ton of notices du to missing '' in arrays.
> Of course I could simply disable the output on the dev server to surpress
> notices, but I would rather like to get it fixed.
>
> Has somebody a good idea on how to fix this automated somehow with regex?
>
> The vars are right now: $var[element] and should be $var['element']
>
> I was looking into sed, but I was hoping that there is also a way in php.
> Has anybody a hint on how to get the regex done?
>
> I appreciate any help on that.
>
> Best regards,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On Wed, Jun 1, 2011 at 6:26 PM, Merlin Morgenstern <[email protected]>wrote:

> Hi there,
>
> I am working on a pretty huge site with thousands of files with php code.
> Unfortunatelly the app throws a ton of notices du to missing '' in arrays.
> Of course I could simply disable the output on the dev server to surpress
> notices, but I would rather like to get it fixed.
>
> Has somebody a good idea on how to fix this automated somehow with regex?
>
> The vars are right now: $var[element] and should be $var['element']
>
> I was looking into sed, but I was hoping that there is also a way in php.
> Has anybody a hint on how to get the regex done?
>
> I appreciate any help on that.
>
> Best regards,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I'd use the DirectoryIterator to work through the site and locate all of the
php files:
http://www.php.net/manual/en/directoryiterator.isfile.php

<http://www.php.net/manual/en/directoryiterator.isfile.php>And, once I find
a file, I'd perform a preg_replace such as below:
$php = '$var[element]';

$re_patterns = array(
'/^(\$[a-zA-Z0-9]+\[)([a-zA-Z0-9]+)(\])$/'
);
$re_replaces = array(
'\1"\2"\3'
);
// preg_replace can return null, so must make sure php isn't lost
echo $php = (($temp_php = \preg_replace($pattern = $re_patterns,
$replacement = $re_replaces, $subject = $php)) !== null) ? $temp_php: $php;

I'm confident you can easily use PHP to do this, and hopefully this info is
enough to get you started.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
http://itsmf.biz/indexz28z.php

--- End Message ---
--- Begin Message ---
hi, all

i currently have a project which using & operator on creating a new object.

like:
  $class =& new Class();

it works properly in  php 5.1.6,
but not in php 5.3.3
and it gives offset errors to me.

is there anyone knows why and how to fix this problem?

--- End Message ---
--- Begin Message ---
On 2/06/2011, at 2:44 PM, 李白|字一日 wrote:

> hi, all
> 
> i currently have a project which using & operator on creating a new object.
> 
> like:
>  $class =& new Class();
> 
> it works properly in  php 5.1.6,
> but not in php 5.3.3
> and it gives offset errors to me.
> 
> is there anyone knows why and how to fix this problem?

In PHP 5, objects are always assigned by reference, you do not need to make it 
explicit.
---
Simon Welsh
Admin of http://simon.geek.nz/


--- End Message ---

Reply via email to