php-general Digest 20 Nov 2009 13:34:35 -0000 Issue 6452

Topics (messages 299948 through 299957):

need a find/replace command to fix my require_once
        299948 by: Daevid Vincent
        299952 by: Ashley Sheridan
        299954 by: Nathan Rixham

Re: Noob question: Making search results clickable.
        299949 by: Nisse Engström
        299950 by: Nisse Engström
        299955 by: Nathan Rixham

Re: Using $$
        299951 by: Arno Kuhl

Re: need browser auto-form predictable fill-in randomizer addon
        299953 by: Nathan Rixham
        299957 by: Bob McConnell

DOM append to the top
        299956 by: Matthew Croud

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
I was reading this: http://pear.php.net/manual/en/standards.including.php
and it states: 

        "Note: include_once and require_once are statements, not functions.
Parentheses should not surround the subject filename." 

I never knew that. I've always (wrongly) used:
 
     require_once('/path/to/my/file');
 
Anyone have a bash command line snippet (or other code is fine too I guess)
that will fix all my directory tree?
 
The tricks are that I think there can be several variations and several
instances with a given file too:
 
     require_once('/path/to/my/file');
     require_once ('/path/to/my/file');
     require_once("/path/to/my/file");
     require_once(ROOTPATH."/my/file");
 
etc. Note the space before the parens, the single vs. double quotes and the
use of a global define.

I think this regex should work:

        require_once\s?\((.*?)\);

I just don't know the magic sed/awk/grep/whatever to do the search and
replace on all my .php files recursively.

This seems like a useful 'routine' to post up on that page, as I'm sure I'm
not the only one who didn't know this little subtlety (considering PHP
doesn't puke on it either).


--- End Message ---
--- Begin Message ---
On Thu, 2009-11-19 at 17:43 -0800, Daevid Vincent wrote:

> I was reading this: http://pear.php.net/manual/en/standards.including.php
> and it states: 
> 
>       "Note: include_once and require_once are statements, not functions.
> Parentheses should not surround the subject filename." 
> 
> I never knew that. I've always (wrongly) used:
>  
>      require_once('/path/to/my/file');
>  
> Anyone have a bash command line snippet (or other code is fine too I guess)
> that will fix all my directory tree?
>  
> The tricks are that I think there can be several variations and several
> instances with a given file too:
>  
>      require_once('/path/to/my/file');
>      require_once ('/path/to/my/file');
>      require_once("/path/to/my/file");
>      require_once(ROOTPATH."/my/file");
>  
> etc. Note the space before the parens, the single vs. double quotes and the
> use of a global define.
> 
> I think this regex should work:
> 
>       require_once\s?\((.*?)\);
> 
> I just don't know the magic sed/awk/grep/whatever to do the search and
> replace on all my .php files recursively.
> 
> This seems like a useful 'routine' to post up on that page, as I'm sure I'm
> not the only one who didn't know this little subtlety (considering PHP
> doesn't puke on it either).
> 
> 

You could try something like this:

find .  -maxdepth 1 -name "*.php" -type f -exec sed -i 's/find
text/replace text/' {} \;

Note that the find and replace strings are regular expressions,
separated by the / character here, so ()'s will need to be escaped as
they have a special meaning in regular expressions. The maxdepth
parameter of find can be set to higher than 1 to let the script work
recursively on files within directories.

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



--- End Message ---
--- Begin Message ---
Daevid Vincent wrote:
> I was reading this: http://pear.php.net/manual/en/standards.including.php
> and it states: 
> 
>       "Note: include_once and require_once are statements, not functions.
> Parentheses should not surround the subject filename." 
> 
> I never knew that. I've always (wrongly) used:
>  
>      require_once('/path/to/my/file');
>  

if it ain't broken don't fix it - why not just ensure you do it the
correct way (or preferred way) in the future.

sure the time could better be invested fixing a bug, writing a test or
documenting something.

s'all your call though :)

--- End Message ---
--- Begin Message ---
On Thu, 19 Nov 2009 17:02:53 -0000, "Ford, Mike" wrote:

>> -----Original Message-----
>> From: Nisse Engström [mailto:news.nospam.0ixbt...@luden.se]
>> 
>> Without actually checking, I don't think "$row[...]"
>> is going to work in double quoted strings. I'm pretty
>> sure it needs to be in braces. You also need to escape
>> the double quotes and put the array indexes in single
>> quotes:
> 
> You should have checked, because "...$row[title]..." is a valid
> alternative for "...{$row['title']}...". 

I didn't know that. It never occured to me to *not*
use single quotes around the index...

> Personally, I never use it because of it not having the same meaning
> outside a double-quoted string -- but it is a documented feature.

Right. I always use braces (or dot-concatenation) for
anything beyond a simple variable name.


/Nisse

--- End Message ---
--- Begin Message ---
On Thu, 19 Nov 2009 15:07:42 +0000, Ashley Sheridan wrote:

> On Thu, 2009-11-19 at 10:09 -0500, Paul M Foster wrote:
>> 
>> Ahem. You are correct. I should have escaped the double quotes. I've
>> *never* made this kind of mistake before. ;-}
> 
> Gonna go to PHP hell for that faux pas!

I'll see you both there.  :-)


/Nisse

--- End Message ---
--- Begin Message ---
Ford, Mike wrote:
>> -----Original Message-----
>> From: Nisse Engström [mailto:news.nospam.0ixbt...@luden.se]
>> Sent: 19 November 2009 14:54
>> To: php-gene...@lists.php.net
>> Subject: Re: [PHP] Noob question: Making search results clickable.
>>
>> On Wed, 18 Nov 2009 10:31:59 -0500, Paul M Foster wrote:
>>
>>> Replace your query with:
>>>
>>> "SELECT title, id FROM videos WHERE topid1 = '$topic'"
>>>
>>> or whatever index you have to select a particular video from your
>> table.
>>> Replace your echo statement above with:
>>>
>>> echo "<a
>> href="video_display.php?video_id=$row[id]">$row[title]</a>";
>>
>> Without actually checking, I don't think "$row[...]"
>> is going to work in double quoted strings. I'm pretty
>> sure it needs to be in braces. You also need to escape
>> the double quotes and put the array indexes in single
>> quotes:
> 
> You should have checked, because "...$row[title]..." is a valid alternative 
> for "...{$row['title']}...".
> 
> Personally, I never use it because of it not having the same meaning outside 
> a double-quoted string -- but it is a documented feature.
> 

yup, which sucks and breaks at the drop of a hat, like..

<?php
$a = array();
$a['val id'] = 123;
echo "something $a[val id] and more";

produces: parse error, expecting `']''

best avoided imho

--- End Message ---
--- Begin Message ---
-----Original Message-----
From: Ford, Mike [mailto:m.f...@leedsmet.ac.uk] 
Sent: 19 November 2009 07:06 PM
To: php-gene...@lists.php.net
Subject: RE: [PHP] Using $$

> -----Original Message-----
> From: Arno Kuhl [mailto:ak...@telkomsa.net]
> Sent: 19 November 2009 12:23
> 
> I was looking at some old code that I'm convinced once worked but now 
> using
> php5 it doesn't seem to work anymore.
> 
> $input = "_REQUEST";
> if (is_array($$input)) {
>     // do something
> }


> I tested something other than a superglobal and it works as expected. 
> What am I missing?


Depends where you have this fragment of code, but possibly the big fat
warning box towards the bottom of
http://php.net/language.variables.variable?

Cheers!

Mike
 --

Thanks for the link Mike, didn't know that. It doesn't say when this was
introduced but I'm sure superglobal variable variables must have worked at
some stage, because I've got code that once worked but doesn't anymore and
it's due to this. There's always a workaround, just not as elegant.

Cheers
Arno



--- End Message ---
--- Begin Message ---
Daevid Vincent wrote:
> I have a form with probably 100+ elements from input, checkbox, select
> boxes, textareas, etc. It's extremely tedious to fill these in all the time
> and submit while developing/testing.
>  
> Anyone know of a plugin to Firefox (or IE for that matter) that will fill in
> the fields, select stuff, check stuff, etc. with some modicum of
> predictability. Random text only goes so far when debugging as you don't
> necessarily know what the field SHOULD contain.
>  

why not kill two birds with one stone and use selenium to test properly
and automate the process?

http://seleniumhq.org/

bit of integration testing certainly won't harm you.

however - to take O.Lavell's comment on board if you can ("If it is
tedious for you it will be tedious for your future users. And as
a rule, they have far less patience than you have.")

regards,

--- End Message ---
--- Begin Message ---
From: Daevid Vincent

> I have a form with probably 100+ elements from input, checkbox, select
> boxes, textareas, etc. It's extremely tedious to fill these in all the
time
> and submit while developing/testing.
> 
> Anyone know of a plugin to Firefox (or IE for that matter) that will
fill in
> the fields, select stuff, check stuff, etc. with some modicum of
> predictability. Random text only goes so far when debugging as you
don't
> necessarily know what the field SHOULD contain.

The Selenium IDE plug-in records a macro when you fill out the form. You
can run, edit and save that macro, or export it to a half dozen
different languages, then copy and edit those scripts, etc. I record
whole session scenarios, export them to Perl and run them through the
Selenium Remote Control server. I manage them with Perl's Test::Harness.
I am slowly building up a regression test suite for a commercial site. I
tried to do it in PHP, but couldn't find a functional test harness that
wasn't OO based. (Unfortunately, after 40 years of procedural
programming, mostly in assembly languages, I have no class.)

One note, the IDE will not import scripts once they are exported. You
can only load scripts that were saved. These appear to be an xhtml
format.

Bob McConnell

--- End Message ---
--- Begin Message ---
Yo!

I have a working form that adds user input to an XML file, it adds the new "item" element to the bottom of the list of previously created "item" elements. I would now like the new elements to be added to the top of the list. So far i've tried using: insertBefore() but i'm still getting elements added to the bottom.

The XML looks like:

<Clothes>
<Item>...</Item>
<Item>...</Item>
<Item>...</Item>
<----- new items are added here
<Clothes>

This is what my code looks like:

$y = $dom -> getElementsByTagName("item");
$dom -> documentElement -> insertBefore($Xitem,$y);

If trying to pass the top most "item" node to insertbefore() but without any luck. Any ideas ?

Cheers
Mongoose

--- End Message ---

Reply via email to