php-general Digest 4 Sep 2012 18:20:52 -0000 Issue 7951
Topics (messages 318979 through 318991):
Re: templeting
318979 by: Simon Schick
318980 by: Lester Caine
318991 by: Adam Richardson
array.sorting.php
318981 by: John Taylor-Johnston
318982 by: David OBrien
318983 by: John Taylor-Johnston
318985 by: Matijn Woudt
318986 by: John Taylor-Johnston
318988 by: Stuart Dallas
318989 by: Matijn Woudt
PHP CURL JSON POST Firebug
318984 by: ioannes.btinternet.com
318987 by: Matijn Woudt
318990 by: ioannes.btinternet.com
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 ---
On Tue, Sep 4, 2012 at 8:16 AM, Louis Huppenbauer
<louis.huppenba...@gmail.com> wrote:
>
> I'm mostly working with twig, a symfony2 framework component.
> I especially like it's template inheritance and the (in my opinion) very
> clear syntax.
>
> http://twig.sensiolabs.org/
Hi, all
I most like to use template-engines that does not allow to write
direct PHP code in the template.
This restricts you to split the logic from the displaying code.
Template-engines I know of:
* Smarty
* Twig
* FLUID
* OPT (Open Power Template)
If you want a bigger list, visit wikipedia:
http://de.wikipedia.org/wiki/Template-Engine#Template-Engines_f.C3.BCr_PHP
http://en.wikipedia.org/wiki/Template_engine_%28web%29#Comparison
What I used most is Twig. For the next project (if it has no
template-engine build in in the system I choose) I'll give OPT a try.
It looks promising ;)
Bye
Simon
--- End Message ---
--- Begin Message ---
tamouse mailing lists wrote:
>I've used smarty in the past and was thinking about that, but PEAR is absolete
>anymore and I don't really know of a good replacement. :-/
I use Smarty as well, but I've never used it from PEAR. I just use the
version downloadable fromhttp://www.smarty.net
I'm still on Smarty2 and we 'maintain' our own copy, but starting a new setup,
Smarty3 just needs a different style of working if you have used 2 in the past.
--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
--- End Message ---
--- Begin Message ---
On Mon, Sep 3, 2012 at 9:14 PM, David McGlone <da...@dmcentral.net> wrote:
> Does anyone use any templeting system for any projects? If so what would
> anyone recommend? I looked at Code Ignitor, but it seems the templeting system
> is optional and left out by default.
>
> --
> Regards
> David M.
Well, for a different take on templating, my web framework is
basically just a combination of input validation and output mechanisms
(templating.) The library takes a functional programming approach in
terms of architecture.
Here's an example of the markup:
http://nephtaliproject.com/documentation/markup/
Page output regions are broken up into pipes, and if one pipe errors
out, it does not impact the other output regions.
It does other things, too (config settings, debugging output, avoid
prompts on back clicks after posting data, convenient PDO wrappers,
etc.), but at its core, it's really a templating framework with input
validation capabilities.
Adam
--
Nephtali: A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com
--- End Message ---
--- Begin Message ---
Hi,
Sorting question. http://www.php.net/manual/en/array.sorting.php
I'm using ksort, which sorts like this.
I don't want to use strolower.
Is there a function/switch in one of the sort functions where I could
get another aphabetical sort?
http://www.php.net/manual/en/array.sorting.php has a lot of options. I,m
not sure which one I should choose.
This is what I get:
LABRADOR CITY
LACOSTA
LARGE
Labrador
Labrador City
Labrador Sea
Lacosta
Large
labrador
labrador sea
lacosta
large
This is what I want:
LABRADOR
Labrador
labrador
LABRADOR CITY
Labrador City
Labrador Sea
labrador sea
LACOSTA
Lacosta
lacosta
LARGE
Large
large
--- End Message ---
--- Begin Message ---
On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston <
jt.johns...@usherbrooke.ca> wrote:
> Hi,
> Sorting question.
> http://www.php.net/manual/en/**array.sorting.php<http://www.php.net/manual/en/array.sorting.php>
> I'm using ksort, which sorts like this.
> I don't want to use strolower.
> Is there a function/switch in one of the sort functions where I could get
> another aphabetical sort?
>
> http://www.php.net/manual/en/**array.sorting.php<http://www.php.net/manual/en/array.sorting.php>has
> a lot of options. I,m not sure which one I should choose.
>
> This is what I get:
>
> LABRADOR CITY
> LACOSTA
> LARGE
> Labrador
> Labrador City
> Labrador Sea
> Lacosta
> Large
> labrador
> labrador sea
> lacosta
> large
>
>
> This is what I want:
>
> LABRADOR
> Labrador
> labrador
> LABRADOR CITY
> Labrador City
> Labrador Sea
> labrador sea
> LACOSTA
> Lacosta
> lacosta
> LARGE
> Large
> large
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
natsort
natcasesort
--- End Message ---
--- Begin Message ---
The problem is I'm sorting the key. The alphabetical thing is in the key.
David OBrien wrote:
On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston
<jt.johns...@usherbrooke.ca <mailto:jt.johns...@usherbrooke.ca>> wrote:
Hi,
Sorting question. http://www.php.net/manual/en/array.sorting.php
I'm using ksort, which sorts like this.
I don't want to use strolower.
Is there a function/switch in one of the sort functions where I
could get another aphabetical sort?
http://www.php.net/manual/en/array.sorting.php has a lot of
options. I,m not sure which one I should choose.
This is what I get:
LABRADOR CITY
LACOSTA
LARGE
Labrador
Labrador City
Labrador Sea
Lacosta
Large
labrador
labrador sea
lacosta
large
This is what I want:
LABRADOR
Labrador
labrador
LABRADOR CITY
Labrador City
Labrador Sea
labrador sea
LACOSTA
Lacosta
lacosta
LARGE
Large
large
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
natsort
natcasesort
--- End Message ---
--- Begin Message ---
On Tue, Sep 4, 2012 at 7:23 PM, John Taylor-Johnston
<jt.johns...@usherbrooke.ca> wrote:
> The problem is I'm sorting the key. The alphabetical thing is in the key.
>
> David OBrien wrote:
>>
Taken from the natsort manual page comments:
<?php
/**
* keyNatSort does a natural sort via key on the supplied array.
*
* @param $array The array to natural sort via key.
* @param $saveMemory If true will delete values from the original
array as it builds the sorted array.
* @return Sorted array on success. Boolean false if sort failed or
null if the object was not an array.
*/
function keyNatSort($array, $saveMemory=false)
{
if(is_array($array))
{
$keys = array_keys($array);
if(natsort($keys))
{
$result = array();
foreach($keys as $key)
{
$result[$key] = $array[$key];
if($saveMemory)
unset($array[$key]);
}
}
else
$result = false;
}
else
$result = null;
return $result;
}
?>
- Matijn
PS. Please bottom post on this and probably any mailing list
--- End Message ---
--- Begin Message ---
David OBrien wrote:
On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston
<jt.johns...@usherbrooke.ca <mailto:jt.johns...@usherbrooke.ca>> wrote:
Hi,
Sorting question. http://www.php.net/manual/en/array.sorting.php
I'm using ksort, which sorts like this.
I don't want to use strolower.
Is there a function/switch in one of the sort functions where I
could get another aphabetical sort?
http://www.php.net/manual/en/array.sorting.php has a lot of
options. I,m not sure which one I should choose.
This is what I get:
LABRADOR CITY
LACOSTA
LARGE
Labrador
Labrador City
Labrador Sea
Lacosta
Large
labrador
labrador sea
lacosta
large
This is what I want:
LABRADOR
Labrador
labrador
LABRADOR CITY
Labrador City
Labrador Sea
labrador sea
LACOSTA
Lacosta
lacosta
LARGE
Large
large
natsort
natcasesort
I'm sorting the key. It doesn't work. ksort is the only choice I have,
right?
Ok, let's approach this question differently.
Right now the frequency of each word is in value.
How do I put the frequency of each word in the key?
I'm fuzzy when it comes to arrays. I can do this is MySQL. All I need is
an id and two varchars and then I know how to sort any way I want. But I
am processing dynamic text files. MySQL is not an option; data changes
too much. PHP is faster and more efficient. I'm just no good at arrays.
Here is my code:
---------------snip-------------------
$mynewstring = "http://foo.com/bigtextfile.txt";
$words = preg_split('/[[:space:]]+/',$mynewstring);
foreach ($words as $word) {
$freq[$word]++;
}
#natcasesort($freq);
ksort($freq);
John
--- End Message ---
--- Begin Message ---
http://php.net/uksort
--
Sent from my leaf blower
On 4 Sep 2012 18:39, "John Taylor-Johnston" <jt.johns...@usherbrooke.ca>
wrote:
>
> David OBrien wrote:
>
>> On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston <
>> jt.johns...@usherbrooke.ca
>> <mailto:jt.johnston@**usherbrooke.ca<jt.johns...@usherbrooke.ca>>>
>> wrote:
>>
>> Hi,
>> Sorting question.
>> http://www.php.net/manual/en/**array.sorting.php<http://www.php.net/manual/en/array.sorting.php>
>> I'm using ksort, which sorts like this.
>> I don't want to use strolower.
>> Is there a function/switch in one of the sort functions where I
>> could get another aphabetical sort?
>>
>>
>> http://www.php.net/manual/en/**array.sorting.php<http://www.php.net/manual/en/array.sorting.php>has
>> a lot of
>> options. I,m not sure which one I should choose.
>>
>> This is what I get:
>>
>> LABRADOR CITY
>> LACOSTA
>> LARGE
>> Labrador
>> Labrador City
>> Labrador Sea
>> Lacosta
>> Large
>> labrador
>> labrador sea
>> lacosta
>> large
>>
>>
>> This is what I want:
>>
>> LABRADOR
>> Labrador
>> labrador
>> LABRADOR CITY
>> Labrador City
>> Labrador Sea
>> labrador sea
>> LACOSTA
>> Lacosta
>> lacosta
>> LARGE
>> Large
>> large
>>
>>
>> natsort
>> natcasesort
>>
> I'm sorting the key. It doesn't work. ksort is the only choice I have,
> right?
>
> Ok, let's approach this question differently.
> Right now the frequency of each word is in value.
> How do I put the frequency of each word in the key?
>
> I'm fuzzy when it comes to arrays. I can do this is MySQL. All I need is
> an id and two varchars and then I know how to sort any way I want. But I am
> processing dynamic text files. MySQL is not an option; data changes too
> much. PHP is faster and more efficient. I'm just no good at arrays.
>
> Here is my code:
> ---------------snip-----------**--------
> $mynewstring =
> "http://foo.com/bigtextfile.**txt<http://foo.com/bigtextfile.txt>
> ";
>
> $words = preg_split('/[[:space:]]+/',$**mynewstring);
>
> foreach ($words as $word) {
> $freq[$word]++;
> }
>
> #natcasesort($freq);
> ksort($freq);
>
> John
>
--- End Message ---
--- Begin Message ---
On Tue, Sep 4, 2012 at 7:38 PM, John Taylor-Johnston
<jt.johns...@usherbrooke.ca> wrote:
>
> David OBrien wrote:
>>
>> On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston
>> <jt.johns...@usherbrooke.ca <mailto:jt.johns...@usherbrooke.ca>> wrote:
>>
>> Hi,
>> Sorting question. http://www.php.net/manual/en/array.sorting.php
>>
>> I'm using ksort, which sorts like this.
>> I don't want to use strolower.
>> Is there a function/switch in one of the sort functions where I
>> could get another aphabetical sort?
>>
>> http://www.php.net/manual/en/array.sorting.php has a lot of
>> options. I,m not sure which one I should choose.
>>
>> This is what I get:
>>
>> LABRADOR CITY
>> LACOSTA
>> LARGE
>> Labrador
>> Labrador City
>> Labrador Sea
>> Lacosta
>> Large
>> labrador
>> labrador sea
>> lacosta
>> large
>>
>>
>> This is what I want:
>>
>> LABRADOR
>> Labrador
>> labrador
>> LABRADOR CITY
>> Labrador City
>> Labrador Sea
>> labrador sea
>> LACOSTA
>> Lacosta
>> lacosta
>> LARGE
>> Large
>> large
>>
>>
>> natsort
>> natcasesort
>
> I'm sorting the key. It doesn't work. ksort is the only choice I have,
> right?
>
> Ok, let's approach this question differently.
> Right now the frequency of each word is in value.
> How do I put the frequency of each word in the key?
>
try array_flip(), keep in mind though, that when two words have the
same frequency, one of them will get lost because the keys are
identical.
> I'm fuzzy when it comes to arrays. I can do this is MySQL. All I need is an
> id and two varchars and then I know how to sort any way I want. But I am
> processing dynamic text files. MySQL is not an option; data changes too
> much. PHP is faster and more efficient. I'm just no good at arrays.
>
> Here is my code:
> ---------------snip-------------------
> $mynewstring = "http://foo.com/bigtextfile.txt";
>
> $words = preg_split('/[[:space:]]+/',$mynewstring);
>
> foreach ($words as $word) {
> $freq[$word]++;
> }
>
> #natcasesort($freq);
> ksort($freq);
>
> John
You can try uksort with a custom compare function.
- Matijn
--- End Message ---
--- Begin Message ---
I am hoping someone can spot what is missing here. I am getting null
result from curl-ing a page with json post variables.
I try this url in my Firefox browser -
http://www.targetsite.com/search.php#somevar.someothervar
(#somevar.someothervar are irrelevant, I think, as I get the curl
variables from Firebug below.)
In Firebug, this shows:
POST http://www.targetsite.com/ajax/search.xml
In Firebug, below this link are tabs for: Headers, Post, Response, XML
and Cookies. Post tab shows like:
JSON
VAR1 1
VAR2 "2012-09-12"
VAR3 null
CACHED []
OPTIONS null
To prove there is output, the Firebug Response tab shows:
<?xml version="1.0" encoding="utf-8"?>
<JSON> various JSON encoded stuff </JSON>
The above is what I am trying to curl.
My php code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
//target page from Firebug above:
curl_setopt($ch, CURLOPT_URL,
"http://www.targetsite.com/ajax/search.xml");
//I was not sure how to represent CACHED [], so set it to null
$data = array(
"VAR1" => 1,
"VAR2" => "2012-09-12",
"VAR3" => null,
"CACHED"=>null,
"OPTIONS"=>null,
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//make the request
$result = curl_exec($ch);
//this returns null
Any ideas where to go with this? Maybe I need to include the Cookies?
I use the above php and curl functions normally so it's all installed on
the server.
John
--- End Message ---
--- Begin Message ---
On Tue, Sep 4, 2012 at 7:35 PM, ioan...@btinternet.com
<ioan...@btinternet.com> wrote:
> I am hoping someone can spot what is missing here. I am getting null result
> from curl-ing a page with json post variables.
>
> I try this url in my Firefox browser -
>
> http://www.targetsite.com/search.php#somevar.someothervar
>
> (#somevar.someothervar are irrelevant, I think, as I get the curl variables
> from Firebug below.)
>
> In Firebug, this shows:
>
> POST http://www.targetsite.com/ajax/search.xml
>
> In Firebug, below this link are tabs for: Headers, Post, Response, XML and
> Cookies. Post tab shows like:
>
> JSON
> VAR1 1
> VAR2 "2012-09-12"
> VAR3 null
> CACHED []
> OPTIONS null
>
> To prove there is output, the Firebug Response tab shows:
>
> <?xml version="1.0" encoding="utf-8"?>
> <JSON> various JSON encoded stuff </JSON>
>
> The above is what I am trying to curl.
>
> My php code:
>
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
> curl_setopt($ch, CURLOPT_POST, 1);
>
> //target page from Firebug above:
> curl_setopt($ch, CURLOPT_URL,
> "http://www.targetsite.com/ajax/search.xml");
>
> //I was not sure how to represent CACHED [], so set it to null
try "CACHED"=>array()
> $data = array(
> "VAR1" => 1,
> "VAR2" => "2012-09-12",
> "VAR3" => null,
> "CACHED"=>null,
> "OPTIONS"=>null,
> );
> curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
>
> //make the request
> $result = curl_exec($ch);
>
> //this returns null
>
> Any ideas where to go with this? Maybe I need to include the Cookies? I use
> the above php and curl functions normally so it's all installed on the
> server.
>
> John
It might be that the site is using sessions/cookies. Have a look at
the header data with firebug.
Not sure if that's the problem, to find out what's really going on, call
echo curl_error($ch);
after curl_exec to find out what went wrong exactly.
If you still don't know how to proceed, paste the result of the
curl_error call in your reply.
- Matijn
--- End Message ---
--- Begin Message ---
On 04/09/2012 18:41, Matijn Woudt wrote:
On Tue, Sep 4, 2012 at 7:35 PM, ioan...@btinternet.com
<ioan...@btinternet.com> wrote:
I am hoping someone can spot what is missing here. I am getting null result
from curl-ing a page with json post variables.
I try this url in my Firefox browser -
http://www.targetsite.com/search.php#somevar.someothervar
(#somevar.someothervar are irrelevant, I think, as I get the curl variables
from Firebug below.)
In Firebug, this shows:
POST http://www.targetsite.com/ajax/search.xml
In Firebug, below this link are tabs for: Headers, Post, Response, XML and
Cookies. Post tab shows like:
JSON
VAR1 1
VAR2 "2012-09-12"
VAR3 null
CACHED []
OPTIONS null
To prove there is output, the Firebug Response tab shows:
<?xml version="1.0" encoding="utf-8"?>
<JSON> various JSON encoded stuff </JSON>
The above is what I am trying to curl.
My php code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
//target page from Firebug above:
curl_setopt($ch, CURLOPT_URL,
"http://www.targetsite.com/ajax/search.xml");
//I was not sure how to represent CACHED [], so set it to null
try "CACHED"=>array()
$data = array(
"VAR1" => 1,
"VAR2" => "2012-09-12",
"VAR3" => null,
"CACHED"=>null,
"OPTIONS"=>null,
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//make the request
$result = curl_exec($ch);
//this returns null
Any ideas where to go with this? Maybe I need to include the Cookies? I use
the above php and curl functions normally so it's all installed on the
server.
John
It might be that the site is using sessions/cookies. Have a look at
the header data with firebug.
Not sure if that's the problem, to find out what's really going on, call
echo curl_error($ch);
after curl_exec to find out what went wrong exactly.
If you still don't know how to proceed, paste the result of the
curl_error call in your reply.
- Matijn
I added the cookies to the post array. I changed php array to
"CACHED"=>array() for the JSON "CACHED":[], and corrected php's null to
NULL. It is not returning any error. The browser was showing 'resource
not present' before I added the cookies to the post array, now it just
returns null $result. Looks like I am transcribing something incorrectly.
John
--- End Message ---