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  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  wrote:
> On Wed, Dec 22, 2010 at 3:34 PM, Bob McConnell  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_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] 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  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



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
 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" 
> Date: Thu, Oct 21, 2010 11:03
> Subject: [PHP] "My truth comes out" [1]
> To: "a...@ashleysheridan.co.uk" 
> Cc: 
>
>
> 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
>  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" 
>> Date: Thu, Oct 21, 2010 10:51
>> Subject: [PHP] "My truth comes out" [1]
>> To: 
>>
>> preg_match("/false/i", $string) ? false : true;
>>
>>
>>
>> On Thu, Oct 21, 2010 at 7:39 PM, Gary  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
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
 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" 
> Date: Thu, Oct 21, 2010 10:51
> Subject: [PHP] "My truth comes out" [1]
> To: 
>
> preg_match("/false/i", $string) ? false : true;
>
>
>
> On Thu, Oct 21, 2010 at 7:39 PM, Gary  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
preg_match("/false/i", $string) ? false : true;



On Thu, Oct 21, 2010 at 7:39 PM, Gary  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] What other languages do you use?

2010-10-10 Thread Russell Dias
For me:

LAMP stack of course.
Javascript and jQuery
Python


Learning new languages open your mind to a whole new set of
possibilities. It also improves the way you code in your language of
choice.  At this point in time, my goals are one language a year.
Eventually I would like to get to a point of being language agnostic
and simply use the tool that is best suited for a particular job.

On Sun, Oct 10, 2010 at 5:56 PM, Richard Quadling  wrote:
> On 8 October 2010 18:30, Nathan Rixham  wrote:
>> As per the subject, not what other languages have you used, but what other
>> languages do you currently use?
>>
>> I guess it may also be interesting to know if:
>>
>> (1) there's any particular reason for you using a different language (other
>> than work/day-job/client requires it)
>>
>> (2) about to jump in to another language
>>
>> Best,
>>
>> Nathan
>
> PHP/HTML/JS/CSS - Normal web dev.
> .BAT - I'm on windows and sometimes a simple bat file works for me.
> T-SQL - Microsoft SQL Server stored procedures/UDFs/etc.
> C - Amending the PECL/Win32Service extension (waiting for karma ... )
>
>
>
> --
> Richard Quadling
> Twitter : EE : Zend
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>
> --
> 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