php-general Digest 19 Mar 2012 12:23:10 -0000 Issue 7734

Topics (messages 317121 through 317130):

Re: CMS identification
        317121 by: Daniel Fenn
        317122 by: Robert Cummings
        317127 by: Stuart Dallas

Re: Getting knotted with quotes encoding - (one possible solution)
        317123 by: Tamara Temple
        317124 by: tamouse mailing lists

Re: Parse errors
        317125 by: tamouse mailing lists

Re: questions about $_SERVER
        317126 by: tamouse mailing lists

Re: Got HTML5 History API + caching LICKED, I think, <grin>
        317128 by: rene7705
        317129 by: rene7705

Using a stream filter to do a search and replace on an XML file.
        317130 by: Richard Quadling

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 ---
Well if the OP has the link to it in the first place then yes that would work.





On Mon, Mar 19, 2012 at 11:21 AM, Ross McKay <ro...@zeta.org.au> wrote:
> On Sun, 18 Mar 2012 23:20:21 +0100, Alain Roger wrote:
>
>>i have a customer who need to update his website but he was not able to
>>tell me more about it.
>>he just told me it's a CMS and sent me a screenshot.
>>[...]
>
> Instead of hoping for a USENET reader to recognise that screenshot, open
> the login page in a web browser and view source. It's likely that there
> will be a meta tag in the head that tells you what the CMS is.
> --
> Ross McKay, Toronto, NSW Australia
> "Let the laddie play wi the knife - he'll learn"
> - The Wee Book of Calvin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
On 12-03-18 06:42 PM, Stuart Dallas wrote:
On 18 Mar 2012, at 22:32, Alain Roger wrote:

ok so here it is: 
http://i220.photobucket.com/albums/dd277/alainroger/cms-login.png

Pass, not one I'm familiar with and a Google Image search for cms login doesn't 
show anything similar. If I were you I'd tell him to give me access to it so I 
can have a look for myself.

On google image search click on the camera icon... then paste in the URL with the screen shot.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
On 19 Mar 2012, at 02:20, Robert Cummings wrote:

> On 12-03-18 06:42 PM, Stuart Dallas wrote:
>> On 18 Mar 2012, at 22:32, Alain Roger wrote:
>> 
>>> ok so here it is: 
>>> http://i220.photobucket.com/albums/dd277/alainroger/cms-login.png
>> 
>> Pass, not one I'm familiar with and a Google Image search for cms login 
>> doesn't show anything similar. If I were you I'd tell him to give me access 
>> to it so I can have a look for myself.
> 
> On google image search click on the camera icon... then paste in the URL with 
> the screen shot.

How freakin' awesome is that?!?!?

http://www.idep-support.com/page.php?srid=33

Thanks Rob!

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
On Tue, 13 Mar 2012 16:35:44 +0200, Arno Kuhl <a...@dotcontent.net> sent:
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
Sent: 13 March 2012 03:25 PM
To: a...@dotcontent.net; php-gene...@lists.php.net
Subject: Re: [PHP] Getting knotted with quotes encoding


Arno Kuhl <a...@dotcontent.net> wrote:

I've been battling with quotes encoding when outputting javascript with
php.
It can't be unique, so I'm hoping someone has a working solution
they're willing to share.

The following works perfectly as long as there aren't any single quotes
in the link text:
        echo "<span onclick=\"insertLink('$sUrl','$sTitle')\"
class='linkSel'>$sTitle</span>";

if $sTitle has the value    What's new    it outputs:
        <span onclick="insertLink('article/whats-new.html','What&#039;s
new')" class='linkSel'>What&#039;s new</span>

It displays fine, but javascript complains with:
        Expected ')'  linkmanager.php Line:525 Char:63


So I fix this by swapping the double and single quotes around:
        echo "<span onclick='insertLink(\"$sUrl\",\"$sTitle\")'
class='linkSel'>$sTitle</span>";

Now for that specific link it outputs:
        <span onclick='insertLink("article/whats-new.html","What&#039;s
new")' class='linkSel'>What&#039;s new</span> And javascript is happy.

But elsewhere there's a link     Fred "Buster" Cox     and it outputs:
        <span onclick='insertLink("article/fred-buster-cox.html","Fred
&quot;Buster&quot; Cox")' class='linkSel'>Fred &quot;Buster&quot;
Cox</span>

Again it displays fine, but javascript complains with:
        Expected ')'  linkmanager.php Line:743 Char:77


So it looks like I can't have links that include single quotes and
double quotes, only one or the other.

One work-around I thought of was to convert any link texts that
included double quotes into single quotes when the content is posted,
and it would then be displayed with single quotes even though the user
entered double quotes. It's far from ideal but it would work, though I
can think of a few situations where it would be quite confusing to the
reader. Are there any other solutions that would allow both types of
quotes without any conversions?

Cheers
Arno


--

You aren't escaping the quotes correctly when they go into your output. You're escaping them for html not javascript. Javascript (like php) escapes single quotes inside a single quote string with a back slash.


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

Thanks for that Ashley.
You're right about the encoding.
I had a line prior to that:
        $sTitle = htmlentities($title, ENT_QUOTES, 'ISO-8859-1', FALSE);
Which encoded the quotes.


I couldn't find anything so made a function, which might be useful for others.
It’s a first shot, I'm sure there are ways to improve performance.
I also changed the encoding to exclude single quotes.
(I'm sure the indenting will get screwed up in the mail)


$sTitle = fixSingleQuotes(htmlentities($title, ENT_COMPAT, 'ISO-8859-1', FALSE));

.....

////////////////////////////////////////////////////////////////////////////////
// convert single quotes to curly quotes, xml compliant
// assumes apostrophes must be between 2 alpha chars
// and any other ' is a single quote
// &#8216; = left single quote
// &#8217; = right single quote and apostrophe
function fixSingleQuotes($sText)
{
        if (strpos($sText, "'") !== FALSE) {
                // there are quotes to convert
                $bOpenQuote = FALSE;
$arrAlpha = explode(' ', "a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z");
                $arrText = str_split($sText);
                while (($pos = strpos($sText, "'")) !== FALSE) {
                        if ($pos == 0) {
                                // must be an open quote in first pos
                                $sText = "&#8216;".substr($sText, 1);
                                $bOpenQuote = TRUE;
                        } else {
if (in_array($arrText[$pos-1], $arrAlpha) AND in_array($arrText[$pos+1], $arrAlpha)) {
                                        // apostrophe
                                        $quote = "&#8217;";
                                } else {
                                        // quote
                                        if (!$bOpenQuote) {
                                                $quote = "&#8216;";
                                                $bOpenQuote = TRUE;
                                        } else {
                                                $quote = "&#8217;";
                                                $bOpenQuote = FALSE;
                                        }
                                }
                                $sText = substr($sText, 0, 
$pos).$quote.substr($sText, $pos+1);
                        }
                }
        }
        return ($sText);

} //fixSingleQuotes()



Cheers
Arno


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




This is interesting. I wasn't aware that javascript reencoded html entities in this way.

I'm wondering, though, wouldn't a call to addslashes work in this case?

--
Tamara Temple
   aka tamouse__

May you never see a stranger's face in the mirror


--- End Message ---
--- Begin Message ---
On Sun, Mar 18, 2012 at 10:19 PM, Tamara Temple
<tamouse.li...@tamaratemple.com> wrote:
> On Tue, 13 Mar 2012 16:35:44 +0200, Arno Kuhl <a...@dotcontent.net> sent:
>
>> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
>> Sent: 13 March 2012 03:25 PM
>> To: a...@dotcontent.net; php-gene...@lists.php.net
>> Subject: Re: [PHP] Getting knotted with quotes encoding
>>
>>
>> Arno Kuhl <a...@dotcontent.net> wrote:
>>
>>> I've been battling with quotes encoding when outputting javascript with
>>> php.
>>> It can't be unique, so I'm hoping someone has a working solution
>>> they're willing to share.
>>>
>>> The following works perfectly as long as there aren't any single quotes
>>> in the link text:
>>>        echo "<span onclick=\"insertLink('$sUrl','$sTitle')\"
>>> class='linkSel'>$sTitle</span>";
>>>
>>> if $sTitle has the value    What's new    it outputs:
>>>        <span onclick="insertLink('article/whats-new.html','What&#039;s
>>> new')" class='linkSel'>What&#039;s new</span>
>>>
>>> It displays fine, but javascript complains with:
>>>        Expected ')'  linkmanager.php Line:525 Char:63
>>>
>>>
>>> So I fix this by swapping the double and single quotes around:
>>>        echo "<span onclick='insertLink(\"$sUrl\",\"$sTitle\")'
>>> class='linkSel'>$sTitle</span>";
>>>
>>> Now for that specific link it outputs:
>>>        <span onclick='insertLink("article/whats-new.html","What&#039;s
>>> new")' class='linkSel'>What&#039;s new</span> And javascript is happy.
>>>
>>> But elsewhere there's a link     Fred "Buster" Cox     and it outputs:
>>>        <span onclick='insertLink("article/fred-buster-cox.html","Fred
>>> &quot;Buster&quot; Cox")' class='linkSel'>Fred &quot;Buster&quot;
>>> Cox</span>
>>>
>>> Again it displays fine, but javascript complains with:
>>>        Expected ')'  linkmanager.php Line:743 Char:77
>>>
>>>
>>> So it looks like I can't have links that include single quotes and
>>> double quotes, only one or the other.
>>>
>>> One work-around I thought of was to convert any link texts that
>>> included double quotes into single quotes when the content is posted,
>>> and it would then be displayed with single quotes even though the user
>>> entered double quotes. It's far from ideal but it would work, though I
>>> can think of a few situations where it would be quite confusing to the
>>> reader. Are there any other solutions that would allow both types of
>>> quotes without any conversions?
>>>
>>> Cheers
>>> Arno
>>>
>>>
>>> --
>>
>>
>> You aren't escaping the quotes correctly when they go into your  output.
>> You're escaping them for html not javascript. Javascript  (like php) escapes
>> single quotes inside a single quote string with a  back slash.
>>
>>
>>  Thanks,
>> Ash
>> http://ashleysheridan.co.uk
>> ---------
>>
>> Thanks for that Ashley.
>> You're right about the encoding.
>> I had a line prior to that:
>>        $sTitle = htmlentities($title, ENT_QUOTES, 'ISO-8859-1', FALSE);
>> Which encoded the quotes.
>>
>>
>> I couldn't find anything so made a function, which might be useful  for
>> others.
>> It’s a first shot, I'm sure there are ways to improve performance.
>> I also changed the encoding to exclude single quotes.
>> (I'm sure the indenting will get screwed up in the mail)
>>
>>
>> $sTitle = fixSingleQuotes(htmlentities($title, ENT_COMPAT,  'ISO-8859-1',
>> FALSE));
>>
>> .....
>>
>>
>> ////////////////////////////////////////////////////////////////////////////////
>> // convert single quotes to curly quotes, xml compliant
>> // assumes apostrophes must be between 2 alpha chars
>> // and any other ' is a single quote
>> // &#8216; = left single quote
>> // &#8217; = right single quote and apostrophe
>> function fixSingleQuotes($sText)
>> {
>>        if (strpos($sText, "'") !== FALSE) {
>>                // there are quotes to convert
>>                $bOpenQuote = FALSE;
>>                $arrAlpha = explode(' ', "a b c d e f g h i j k l m n o p q
>> r s t  u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z");
>>                $arrText = str_split($sText);
>>                while (($pos = strpos($sText, "'")) !== FALSE) {
>>                        if ($pos == 0) {
>>                                // must be an open quote in first pos
>>                                $sText = "&#8216;".substr($sText, 1);
>>                                $bOpenQuote = TRUE;
>>                        } else {
>>                                if (in_array($arrText[$pos-1], $arrAlpha)
>>  AND   in_array($arrText[$pos+1], $arrAlpha)) {
>>                                        // apostrophe
>>                                        $quote = "&#8217;";
>>                                } else {
>>                                        // quote
>>                                        if (!$bOpenQuote) {
>>                                                $quote = "&#8216;";
>>                                                $bOpenQuote = TRUE;
>>                                        } else {
>>                                                $quote = "&#8217;";
>>                                                $bOpenQuote = FALSE;
>>                                        }
>>                                }
>>                                $sText = substr($sText, 0,
>> $pos).$quote.substr($sText, $pos+1);
>>                        }
>>                }
>>        }
>>        return ($sText);
>>
>> } //fixSingleQuotes()
>>
>>
>>
>> Cheers
>> Arno
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
> This is interesting. I wasn't aware that javascript reencoded html entities
> in this way.
>
> I'm wondering, though, wouldn't a call to addslashes work in this case?

Wow, no it wouldn't. At least not the way it needs to to be more
universal. I spent quite a bit of time pondering this and testing
things, and finally came up with this writeup:
http://wiki.tamaratemple.com/Technology/HandlingQuotesInJavascript

Given the final outcome of needing to write a base64 codec for
javascript, perhaps Arno's solution above it better?

--- End Message ---
--- Begin Message ---
On Sun, Mar 18, 2012 at 2:18 PM, Tim Streater <t...@clothears.org.uk> wrote:
> On 18 Mar 2012 at 17:46, Simon J Welsh <si...@welsh.co.nz> wrote:
>
>> This is expected. The error doesn't occur to the second file is included, so
>> everything in the first included file is parsed and run before execution is
>> halted.
>
> Simon,
>
> Thanks for that. Looks like I should be able to catch most places where an 
> error might occur.

I tend to do a syntax check with php -l on the command line after
editing to see whatever errors might occur before I run the code on
the web site.

--- End Message ---
--- Begin Message ---
On Sat, Mar 10, 2012 at 7:43 PM, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
> On Mar 10, 2012, at 3:53 PM, tamouse mailing lists wrote:
>> On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling <tedd.sperl...@gmail.com> 
>> wrote:
>>> That's correct, but to access those variables outside of their scope (such 
>>> as a function) you do via a SuperGlobal, namely $GLOBAL['whatever'].
>>>
>>> As such, there are no "globals" in PHP other than SuperGlobals. As I said, 
>>> if I'm wrong, please show me otherwise.
>>
>> I guess I don't know what you mean by "globals". I know what globals
>> are, but not "globals".
>
> I don't understand your question. I know what questions are, but not your 
> question. :-)

Well, I've been pondering this for a while, and now I'm sure.

 -> kill file

--- End Message ---
--- Begin Message ---
On Mon, Mar 19, 2012 at 11:07 AM, Ege Sertçetin <sertce...@itu.edu.tr>wrote:

> Press F12 for developer tools. Then select browser mode to ie8 or ie7.
>
> Oh SWEET :) Didn't know that, will do it right now! :)

--- End Message ---
--- Begin Message ---
On Mon, Mar 19, 2012 at 11:24 AM, rene7705 <rene7...@gmail.com> wrote:

>
>
> On Mon, Mar 19, 2012 at 11:07 AM, Ege Sertçetin <sertce...@itu.edu.tr>wrote:
>
>> Press F12 for developer tools. Then select browser mode to ie8 or ie7.
>>
>> Oh SWEET :) Didn't know that, will do it right now! :)
>

With this tip, I've just fixed the remaining IE8 and IE7 bugs.
http://mediabeez.ws and the zip available for download there have been
updated just now..

--- End Message ---
--- Begin Message ---
Hello.

Just learning about stream filtering and have 2 questions I hope
someone can give me some pointers on.


1 - Bucketing.

In reading a bit about how this works, the data is passed in chunks
through the filter - known as a bucket brigade.

How does this work if, for example, the search string is chopped by
the bucketing system? It would seem that you would end up with 2 parts
of the search element, neither would be matched for replacing and then
the whole element would be reconstituted in the output.

My filter method is ...

        function filter($r_In, $r_Out, &$i_Consumed, $b_Closing)
                {
                while ($o_Bucket = stream_bucket_make_writeable($r_In))
                        {
                        $o_Bucket->data = preg_replace('`<(/?)(\d+)`', 
'<$1fixed_$2',
$o_Bucket->data);
                        $i_Consumed += $o_Bucket->datalen;
                        stream_bucket_append($r_Out, $o_Bucket);
                        }

                return PSFS_PASS_ON;
                }

This is working fine (so far as I can tell as SimpleXMLIterator is now
happy to read the XML file), but I'm guessing I'm missing something
here if my understanding is correct.




2 - Stream wrapping.

At the moment, we download a .gz file and decompress it into the .xml
file. I know I can use a zlib:// stream wrapper to save me having to
decode the .gz file first. This means smaller downloads and less
storage. We can even use the zlib:// filter on the URL, but we cache
the .gz file locally, so that isn't important.

But for a small set of files (their origin is known, so I can create a
rule for this issue), I have to expand the .gz file first and then fix
the file using the filter above. I then have two paths to load the xml
- either a zlib:// decompress stream or a straight local file.

I'd like to work out how to create a stream wrapper to allow me to say
SOMETHING like ...

$o_MySXI = new 
SimpleXMLIterator('xml.NoNumericTags://compress.zlib:///development/BadlyFormed.gz');

If this was possible, I'd be a LOT happier and could simply stream
from the .gz files without needing to hold onto anything.


Ideas/suggestions/examples/code gratefully received.

Regards,

Richard.

-- 
Richard Quadling
Twitter : EE : Zend : Fantasy Shopper
@RQuadling : http://e-e.com/M_248814.html : http://bit.ly/9O8vFY :
http://fan.sh/106/5tw

--- End Message ---

Reply via email to