Re: [PHP] $$var

2011-03-06 Thread Russell Dias
Hi Ashim,

These are called Variable Variables. Ideally they should be avoided,
as they introduce unnecessary legibility issues.

This is what it does in a nutshell, it's actually quite simple:

$foo = 'bar';
$bar = 'foobar';
echo $$foo;//This prints foobar

What it does is, take the value of $foo (which is 'bar') and if a
variable exists by that name, it will go forth and print the value of
$bar; In this case foobar.
On Sun, Mar 6, 2011 at 11:12 PM, Ashim Kapoor ashimkap...@gmail.com wrote:
 Dear All,

 I was reading the php manual for session_register, and I found the following
 line there : -


 $_SESSION[$var] = $$var;

 Why do I need $$ there ? Can someone explain?

 Thank you,
 Ashim


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Stripslashes

2010-12-22 Thread Russell Dias
stripslashes() is rife with gaping security holes.  For mysql
insertion rely on mysql_real_escape_string() or alternatively, you can
use prepared statements.

For outputting data on the page you should ideally be using
htmlspecialchars($var, ENT_QUOTES);

cheers,
Russ

On Thu, Dec 23, 2010 at 6:48 AM, Ravi Gehlot r...@ravigehlot.net wrote:
 On Wed, Dec 22, 2010 at 3:34 PM, Bob McConnell r...@cbord.com wrote:

 From: Ravi Gehlot

  What are these magic quotes anyways?. What are they used for?
 escaping?

 I wasn't there at the time, but I gather that the general idea was to
 automagically insert escape characters into data submitted from a form.
 However, they used a backslash as the escape character, which is not
 universally recognized across database engines. Even the SQL standard
 defines an escape as a single quote character.

 We used to have magic quotes enabled, and came up with the following
 code to clean up the mess it caused.

    // If magic quotes is on, we want to remove slashes
    if (get_magic_quotes_gpc()) {
      // Magic quotes is on
      $response = stripslashes($_POST[$key]);
    } else {
      $response = $_POST[$key];
    }

 For future releases of PHP, this will also need a check to see if
 get_magic_quotes_gpc() exists first.

 Bob McConnell

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 Bob,

 Thank you very much. This is good information. What I found out from
 http://us2.php.net/manual/en/function.stripslashes.php was the following:
 An example use of *stripslashes()* is when the PHP directive
 magic_quotes_gpchttp://us2.php.net/manual/en/info.configuration.php#ini.magic-quotes-gpcis
 *on* (it's on by default), and you aren't inserting this data into a place
 (such as a database) that requires escaping. For example, if you're simply
 outputting data straight from an HTML form. 

 So that means that stripslashes() isn't intended for DB insertions but only
 straight output. So I will remove it from my code.

 Thanks,
 Ravi.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] My truth comes out [1]

2010-10-21 Thread Russell Dias
preg_match(/false/i, $string) ? false : true;



On Thu, Oct 21, 2010 at 7:39 PM, Gary php-gene...@garydjones.name wrote:
 Is there any nice way to convert a string containing either TRUE or
 FALSE to a bool with the appropriate value? I know I can just if
 (strcmp... but, as the song goes on to say ...ugly, so ugly, it's ugly[1]

 Footnotes:
 [1]  Mask, Henry Rollins

 --
 Gary


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] My truth comes out [1]

2010-10-21 Thread Russell Dias
I'm curious to know why 'thats as bad as an if' ?

It's simple, concise, understandble and does the job. So, I'm curious
to know why exactly its bad?

On Thu, Oct 21, 2010 at 8:01 PM, a...@ashleysheridan.co.uk
a...@ashleysheridan.co.uk wrote:
 That's as bad as an if!

 What about using settype() on the string? I've not tested it, but it looks 
 like it should do the trick.

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

 - Reply message -
 From: Russell Dias rus...@gmail.com
 Date: Thu, Oct 21, 2010 10:51
 Subject: [PHP] My truth comes out [1]
 To: php-general@lists.php.net

 preg_match(/false/i, $string) ? false : true;



 On Thu, Oct 21, 2010 at 7:39 PM, Gary php-gene...@garydjones.name wrote:
 Is there any nice way to convert a string containing either TRUE or
 FALSE to a bool with the appropriate value? I know I can just if
 (strcmp... but, as the song goes on to say ...ugly, so ugly, it's ugly[1]

 Footnotes:
 [1]  Mask, Henry Rollins

 --
 Gary


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] My truth comes out [1]

2010-10-21 Thread Russell Dias
Whats wrong with an if *construct* ? I understand that the ternary
operator is another way of doing it. Using it in such a small scenario
is perfectly justifiable. Its ridiculous to use in more complicated
scenarious because of readability issues.

Direct string comparison? You suggested yet another function call,
settype I believe. Please do not make benchmark claims without any
data.


On Thu, Oct 21, 2010 at 8:11 PM, a...@ashleysheridan.co.uk
a...@ashleysheridan.co.uk wrote:
 Because it is an if statement, just in a different form, and preg_match is 
 more computational expensive than a direct string comparison.

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

 - Reply message -
 From: Russell Dias rus...@gmail.com
 Date: Thu, Oct 21, 2010 11:03
 Subject: [PHP] My truth comes out [1]
 To: a...@ashleysheridan.co.uk a...@ashleysheridan.co.uk
 Cc: php-general@lists.php.net


 I'm curious to know why 'thats as bad as an if' ?

 It's simple, concise, understandble and does the job. So, I'm curious
 to know why exactly its bad?

 On Thu, Oct 21, 2010 at 8:01 PM, a...@ashleysheridan.co.uk
 a...@ashleysheridan.co.uk wrote:
 That's as bad as an if!

 What about using settype() on the string? I've not tested it, but it looks 
 like it should do the trick.

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

 - Reply message -
 From: Russell Dias rus...@gmail.com
 Date: Thu, Oct 21, 2010 10:51
 Subject: [PHP] My truth comes out [1]
 To: php-general@lists.php.net

 preg_match(/false/i, $string) ? false : true;



 On Thu, Oct 21, 2010 at 7:39 PM, Gary php-gene...@garydjones.name wrote:
 Is there any nice way to convert a string containing either TRUE or
 FALSE to a bool with the appropriate value? I know I can just if
 (strcmp... but, as the song goes on to say ...ugly, so ugly, it's ugly[1]

 Footnotes:
 [1]  Mask, Henry Rollins

 --
 Gary


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: My truth comes out [1]

2010-10-21 Thread Russell Dias
I would stay clear of the ternary operator in nested coditions, for
obvious reasons. If it can fit in a single line and is essentially
clear in its message I dont see why not to use it.

On Thu, Oct 21, 2010 at 8:39 PM, Gary php-gene...@garydjones.name wrote:
 Russell Dias wrote:

 preg_match(/false/i, $string) ? false : true;

 ,
 | $foo = (strcmp('true', $string) == 0);
 `
 works as well :) I don't like those kinds of things for this purpose
 because it takes longer for people new to the code to read and
 understand it than, say
 ,
 | (boolean) $string;
 `
 (which in my case does a pretty meaningless conversion)

 No, I was just wondering whether I had missed some construct in the
 language that might the conversion for me, and be obvious to
 PHP-heads. No problem that there doesn't seem to be.


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Scraping Multiple sites

2010-10-02 Thread Russell Dias
I'm currently stuck on a little problem. I'm using cURL in conjunction
with DOMDocument and Xpath to scrape data from a couple of websites.
Please note that is only for personal and educational purposes.

Right now I have 5 independent scripts (that traverse through 5
websites) that run via a cron tab every 12 hours. However, as you may
have guessed this is a scalability nightmare. If my list of websites
to scrape grows I have to create another independent script and run it
via cron.

My knowledge of OOP is fairly basic as I have just gotten started with
it. However, could anyone perhaps suggest a design pattern that would
suit my needs? My solution would be to create an abstract class for
the web crawler and then simply extend it per website I add on.
However, as I said my experience with OOP is almost non-existant
therefore I have no idea how this would scale. I want this 'crawler'
to be one application which can run via one cron rather than having n
amount of scripts for each websites and having to manually create a
cron each time.

Or does anyone have any experience with this sort thing and could
maybe offer some advice?

I'm not limited to using PHP either, however due to hosting
constraints Python would most likely be my only other alternative.

Any help would be appreciated.

Cheers,
Russell

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php