Re: [PHP] templeting

2012-09-04 Thread Simon Schick
On Tue, Sep 4, 2012 at 8:16 AM, Louis Huppenbauer
 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

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



Re: [PHP] templeting

2012-09-04 Thread Lester Caine

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



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



[PHP] array.sorting.php

2012-09-04 Thread John Taylor-Johnston

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



Re: [PHP] array.sorting.php

2012-09-04 Thread David OBrien
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
> 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.phphas
>  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


Re: [PHP] array.sorting.php

2012-09-04 Thread John Taylor-Johnston

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




[PHP] PHP CURL JSON POST Firebug

2012-09-04 Thread ioan...@btinternet.com
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 []
OPTIONSnull

To prove there is output, the Firebug Response tab shows:


 various JSON encoded stuff 

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

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



Re: [PHP] array.sorting.php

2012-09-04 Thread Matijn Woudt
On Tue, Sep 4, 2012 at 7:23 PM, John Taylor-Johnston
 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:



- Matijn

PS. Please bottom post on this and probably any mailing list

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



Re: [PHP] array.sorting.php

2012-09-04 Thread John Taylor-Johnston


David OBrien wrote:
On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston 
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


Re: [PHP] PHP CURL JSON POST Firebug

2012-09-04 Thread Matijn Woudt
On Tue, Sep 4, 2012 at 7:35 PM, 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 []
> OPTIONSnull
>
> To prove there is output, the Firebug Response tab shows:
>
> 
>  various JSON encoded stuff 
>
> 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

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



Re: [PHP] array.sorting.php

2012-09-04 Thread Stuart Dallas
http://php.net/uksort

-- 
Sent from my leaf blower
On 4 Sep 2012 18:39, "John Taylor-Johnston" 
wrote:

>
> David OBrien wrote:
>
>> 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
>> 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.phphas
>>  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
>


Re: [PHP] array.sorting.php

2012-09-04 Thread Matijn Woudt
On Tue, Sep 4, 2012 at 7:38 PM, John Taylor-Johnston
 wrote:
>
> David OBrien wrote:
>>
>> On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston
>> 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

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



Re: [PHP] PHP CURL JSON POST Firebug

2012-09-04 Thread ioan...@btinternet.com



On 04/09/2012 18:41, Matijn Woudt wrote:

On Tue, Sep 4, 2012 at 7:35 PM, 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 []
OPTIONSnull

To prove there is output, the Firebug Response tab shows:


 various JSON encoded stuff 

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

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



Re: [PHP] templeting

2012-09-04 Thread Adam Richardson
On Mon, Sep 3, 2012 at 9:14 PM, David McGlone  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

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



Re: [PHP] array.sorting.php

2012-09-04 Thread Matijn Woudt
On Tue, Sep 4, 2012 at 9:20 PM, John Taylor-Johnston
 wrote:
>
> 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
>
>
> Custom compare function?

Yes, for example:
function insensitive_uksort($a,$b) {
return strtolower($a)http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array.sorting.php

2012-09-04 Thread John Taylor-Johnston

Matijn Woudt wrote:

Taken from the natsort manual page comments:

  


I've tried it.
I don't see it sorting anything?
http://cegepsherbrooke.qc.ca/~languesmodernes/test/keynatsort.php

$words = preg_split('/[[:space:]]+/',$mynewstring);
foreach ($words as $word) {
   $freq[$word]++;
}

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

keyNatSort($freq);

echo "\n";
foreach ($freq as $key => $val) {
#   echo "$key = $val \n";
   echo "".str_replace("_", " ", $key)."$val\n";
}
echo "\n";

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



Re: [PHP] array.sorting.php

2012-09-04 Thread Matijn Woudt
On Tue, Sep 4, 2012 at 9:33 PM, John Taylor-Johnston
 wrote:
> Matijn Woudt wrote:
>>
>> Taken from the natsort manual page comments:
>>
>> > /**
>>  * 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.
>>  */
>>
>> PS. Please bottom post on this and probably any mailing list
>>
>
>
> I've tried it.
> I don't see it sorting anything?
> http://cegepsherbrooke.qc.ca/~languesmodernes/test/keynatsort.php
>
>
> $words = preg_split('/[[:space:]]+/',$mynewstring);
> foreach ($words as $word) {
>$freq[$word]++;
> }
>
> 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;
> }
>
> keyNatSort($freq);

Try :
$freq = keyNatSort($freq);

- Matijn

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