php-general Digest 6 Feb 2011 18:04:00 -0000 Issue 7169

Topics (messages 311166 through 311172):

Re: Design question
        311166 by: Jason Pruim

Re: Bilingual strtotime()
        311167 by: Per Jessen
        311168 by: Per Jessen
        311169 by: Peter Lind
        311170 by: Ashley Sheridan

String length output in php-generated response
        311171 by: Florin Jurcovici

latest posts help
        311172 by: Michael Simiyu

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 ---

On Feb 5, 2011, at 6:46 PM, Paul M Foster wrote:

On Sat, Feb 05, 2011 at 11:11:57AM -0500, [email protected] wrote:

Morning everyone!

I have a design question... No it's not about the interior of my
house... although I could use some help with that as well...

I am working on a framework for my own use (And maybe one day will
beat out the popular frameworks! Hey I can dream right? :)) and to
increase my knowledge.

Here's my current index page:

DJ_doctype("HTML4S");
DJ_head("Double J FrameWork", $cfgCss, $cfgMeta);
DJ_modules("navigation", "option");
DJ_page("main_content.html", "mainContent");
DJ_dbconnect($cfgDatabase);

DJ_footer("copywrite", "Double J Web Design");

"Copywrite" should be "copyright" in this context.


It all works perfectly but I'm starting to question having a bunch of
function calls like that or should I simply have a big master
DJ_displayPage() call?

Is this index page a front controller, or are there separate page
controllers? If the calls are all *identical*, then you can stuff them
into a single function call. The biggest problem with this is variable
visibility. You'll have to monitor that and decide if it's worth it. In
my case, I use page controllers where all the important variables are
declared. If I put a "render()" function at the bottom, I'd have to pass
in all those variables (on the stack) rather than simply have them
visible to the template page that I "include()" at the bottom of the
page controller.

Right now in my simple test pages the variables are very standard but I will keep an eye on it to see if I need to change to a different system.

I'm leaning more towards doing a page controller. I've always liked the way that I can simplify the display of pages especially with regards to updates in the layout by just having a index page that controls the entire site.



or should I have my framework create the html files? Has anyone gone
down this road before? any pitfalls I should watch out for that aren't
in google yet? :)

Some of this depends on your overall application architecture, which is
where the front contoller/page controller question above comes from.

Thanks for the insight! I'll be keeping these points in mind in my work!



--- End Message ---
--- Begin Message ---
Alexis wrote:

> On 05/02/11 13:23, Per Jessen wrote:
>> Alexis wrote:
>>
>>> Hi,
>>>
>>> Living in Canada, and being a bilingual country, I have data I am
>>> processing which includes dates in both English and French.
>>>
>>> I was wondering if there was a way to use the strtotime() function
>>> when the months are in one or the other of the above two languages?
>>
>> Sure, strftime() is locale-sensitive. Set the locale().
>>
>>
>>
> 
> Thanks
> 
> But what if the locale is in two possible languages, all mixed
> together?

You have to decide then:

1) display in language#1
2) display in language#2
3) display in both. 




-- 
Per Jessen, Zürich (4.6°C)


--- End Message ---
--- Begin Message ---
Alexis wrote:

> I was wondering if there was a way to use the strtotime() function
> when the months are in one or the other of the above two languages?

Ah, I misread this earlier - strtotime(), not strftime().  You're
talking about transforming from text to a locale()-neutral format.  I
don't think strtotime() is locale-sensitive - according to the manual:

"The function [strtotime] expects to be given a string containing an
English date format"



-- 
Per Jessen, Zürich (4.6°C)


--- End Message ---
--- Begin Message ---
On Feb 6, 2011 11:16 AM, "Per Jessen" <[email protected]> wrote:
>
> Alexis wrote:
>
> > I was wondering if there was a way to use the strtotime() function
> > when the months are in one or the other of the above two languages?
>
> Ah, I misread this earlier - strtotime(), not strftime().  You're
> talking about transforming from text to a locale()-neutral format.  I
> don't think strtotime() is locale-sensitive - according to the manual:
>
> "The function [strtotime] expects to be given a string containing an
> English date format"
>
>
>

Strtotime can read a number of formats, but does (from experience) have
problems with some. It won't work with textual dates in anything but
English, far as I know.

Regards
Peter

--- End Message ---
--- Begin Message ---
On Sun, 2011-02-06 at 11:24 +0100, Peter Lind wrote:

> On Feb 6, 2011 11:16 AM, "Per Jessen" <[email protected]> wrote:
> >
> > Alexis wrote:
> >
> > > I was wondering if there was a way to use the strtotime() function
> > > when the months are in one or the other of the above two languages?
> >
> > Ah, I misread this earlier - strtotime(), not strftime().  You're
> > talking about transforming from text to a locale()-neutral format.  I
> > don't think strtotime() is locale-sensitive - according to the manual:
> >
> > "The function [strtotime] expects to be given a string containing an
> > English date format"
> >
> >
> >
> 
> Strtotime can read a number of formats, but does (from experience) have
> problems with some. It won't work with textual dates in anything but
> English, far as I know.
> 
> Regards
> Peter


Is there an example of the different date formats so that we can see
what we're working with here? It sounds like it might require a little
manual intervention first (str_replace() maybe) in order for this to
work.

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



--- End Message ---
--- Begin Message ---
Hi.

I'm trying to build myself a small JSON-RPC server using PHP.

Using wireshark, here's the conversation:

Request:
        POST /.../service.php?nocache=1297004648751 HTTP/1.1
        User-Agent: Opera/9.80 (X11; Linux i686; U; en) Presto/2.7.62 
Version/11.01
        Host: localhost
        Accept: text/html, application/xml;q=0.9, application/xhtml+xml,
image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
        Accept-Language: en-US,en;q=0.9
        Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1
        Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
        Referer: http://localhost/ssd/php/testrpc/build/
        Connection: Keep-Alive, TE
        TE: deflate, gzip, chunked, identity, trailers
        Content-Length: 80
        Content-Type: application/json
        Pragma: no-cache
        Cache-Control: no-cache
        X-Qooxdoo-Response-Type: application/json
        Content-Transfer-Encoding: binary

        
{"service":"test.service","method":"method","id":1,"params":[{"code":"client"}]}
 said it, Bush junior proved it
Response:
        HTTP/1.1 200 OK
        Date: Sun, 06 Feb 2011 15:04:08 GMT
        Server: Apache/2.2.14 (Ubuntu)
        Accept-Ranges: bytes
        X-Powered-By: PHP/5.3.2-1ubuntu4.7
        Keep-Alive: timeout=15, max=100
        Connection: Keep-Alive
        Transfer-Encoding: chunked
        Content-Type: application/json; charset=UTF-8

        6f
        
{"id":2,"result":{"service":"test.service","method":"method","id":2,"params":[{"code":"client"}]},"error":null}
        0

The code to handle the request is:

        <?php

        $request = json_decode($GLOBALS['HTTP_RAW_POST_DATA']);

        $response = (object) array(
                "id" => $request->id,
                "result" => $request,
                "error" => null
        );

        header("Content-Type: application/json; charset=UTF-8", true);
        print json_encode($response);

        ?>

The "6f" above is the length of the output in hex (I tried with
various lengths of the string, it is always correct), the 0 at the end
is probably some C-like string termination mark.

Now, it seems the client (some JavaScript running in Firefox) has no
problem decoding the answer, in spite of the hex length placed at the
beginning. However, I can't rely on browsers playing nicely with
incorrect JSON, so I would very much like to generate an output
without the length of the response written as hex at the beginning,
and without the terminating 0. What am I doing wrong? Why does the
length of the string get written?

I tried concatenation of an empty string at the beginning and at the
end, supposing that for some reason json_encode() doesn't produce a
plain string, and hoping that concatenating it to a proper string
would produce a plain string, but it didn't help either.

Before posting to the list, I tried searching for the problem on the
web, and also experimented by outputting plain, hand-written strings.
It didn't really help. Maybe it's a setup problem? My problem is, php
is absolutely new to me, so I don't even know how to start diagnosing
the problem (I started experimenting just a few hours ago).

To decide whether it's a setup problem, here's the development platform:
        OS: Kubuntu 10.04.1 LTS
        Apache: Apache/2.2.14 (Ubuntu)
        PHP: 1.0.5-dev
        json version: 1.2.1

I don't think the browser is relevant, since it behaves the same in
Opera and Firefox, and it doesn't happen in the browser, it happens on
the server, since that's what wireshark shows.

TIA,

flj

-- 
In politics, stupidity is not a handicap. (Napoleon)

--- End Message ---
--- Begin Message --- hello , am working on showing the last 3 posts showed on a message board ( bitweaver ) and i would like to know what to add on the below line of code to show the last 3 this is what i have that shows the last post

Code:
<a href="{$board.last.url}" title="{$board.last.title| default:"Post..."}">{$board.last.title|default:"Post..."|truncate:40}</ a>


what should i add to the code above to pull the last 3 posts so i could have it like this... (the code below just shows the latest in a list format )

Code:
{if !empty($board.last)}
&raquo;&nbsp;<a href="{$board.last.url}" title="{$board.last.title| default:"Post..."}">{$board.last.title|default:"Post..."|truncate:40}</ a>
               <br/>
&raquo;&nbsp;<a href="{$board.last.url}" title="{$board.last.title|default:"Post..."}">{$board.last.title| default:"Post..."|truncate:40}</a>
               <br/>
&raquo;&nbsp;<a href="{$board.last.url}" title="{$board.last.title|default:"Post..."}">{$board.last.title| default:"Post..."|truncate:40}</a>
               <br/>
                    {/if}



Best Regards
Michael S.



--- End Message ---

Reply via email to