Re: [PHP] Question about creating php files from a form

2010-05-13 Thread Paul M Foster
On Thu, May 13, 2010 at 11:53:54PM -0400, Kevin wrote:



> /On a side note:
> I am having some issues with connecting to a SQLite database right now
> ... I'm getting the following error "Fatal Error: 'sqlite_open' is an
> unknown function"
> But I'm putting that on the side right now.

I think the docs are still screwed up. Try sqlite3_open() instead and
see if that works. Also, check phpinfo() to see if the SQLite/SQLite3
modules are loaded.

Paul

-- 
Paul M. Foster

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



Re: [PHP] Append Dom Document

2010-05-13 Thread Nathan Nobbe
>
> I am not sure what you mean in your second point, but I can explain the
> first one. I am using PHP to parse RSS feeds, so that is why they all look
> the same.
>

wow thats hilarious, you can see how little ive worked w/ rss feeds, read
*none*


> Or, what do you mean here? I checked out your example, but my problem here
> is that I cannot get the XML Dom document to append when I make a new
> selection. I am hoping that it would create a new sub document of some sort
> beneath the new one, instead of overwriting the entire document.
>

umm, i dont see you making any modifications to the original document,
$xmlDoc in your code.  thats why i suggested simple xml, its the go-to imo
if all you need to do is traverse an existing document.  DOM is much better
if you need to edit the document.  having said that if you wanted to append
a new DOMNode to an existing one, you would use the appendChild() method.


> Am I making sense here?


no because youre not editing the DOMDocument in your code, youre just
reading a document; what is getting overwritten here?  im not entirely sure
what youre trying to accomplish.

-nathan


Re: [PHP] Question about creating php files from a form

2010-05-13 Thread Kevin

Ashley Sheridan wrote:

On Thu, 2010-05-13 at 23:07 -0400, Kevin wrote:

Hello All,

I am trying to figure out how to create files when a user submits a form ...
I have seen something about '*fopen*' , is that the direction I should 
be going?


Here is what I am trying to accomplish:

I am creating a program to keep track of recipes for my wife. I have 
have page set up where she can put the name of the recipe, the 
ingredients, and the amounts of each ingredient.

Then she clicks "Submit"

I would like a html file with the name of the recipe to be created ie 
*cookies.html  *with a link to the cookies.html created on another page.

*
*I hope this makes sense,  and thank you all for your time...

- - Kevin




It might sound overkill, but I'd use a database for this. All the 
recipes can be stored in a MySQL database, and then you can use a 
simple couple of queries to produce the recipe list and the recipe 
pages dynamically. This also has the advantage that it's very easy to 
search the recipe list when it becomes larger, and if you ever want to 
change the layout/presentation of the whole system you won't have to 
recreate all the recipe pages.


The DB could have several columns labelled: id, name, ingredients, method

So, the form page (lets assume it's called add.php) could submit to 
itself which then adds the recipe to the DB with a query like:


INSERT INTO recipes(name, ingredients, method) VALUES($name, 
$ingredients, $method)


This is only a very simple example which could be extended to use 
another table for ingredients for a recipe. Don't forget to sanitise 
any input coming from the form with mysql_real_escape_string() for 
inserting it into the DB.


The list.php page could just use a simple query like:

SELECT id, name FROM recipes

And then create a link to each recipe in the form: 
recipe.php?recipe=id (where id is the numerical value used in the DB) 
and that would then use a query like:


SELECT * FROM recipe WHERE id=$recipe

MySQL is available on most hosting that you'll find has support for 
PHP, and every Linux distribution I've seen has it too.


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



Thank you Ash for the quick reply.

I was actually looking at using a database too... and I am testing out a 
few different ones (SQLite and MySQL)

I appreciate the extra information, it will be helpful in the future :-)

/On a side note:
I am having some issues with connecting to a SQLite database right now 
... I'm getting the following error "Fatal Error: 'sqlite_open' is an 
unknown function"

But I'm putting that on the side right now.

/I wanted to try a different approach by just creating  the recipes in  
individual  html files for the time being.

Do happen to know how to create html files from a php form?

Thank you.



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



Re: [PHP] Question about creating php files from a form

2010-05-13 Thread Ashley Sheridan
On Thu, 2010-05-13 at 23:07 -0400, Kevin wrote:

> Hello All,
> 
> I am trying to figure out how to create files when a user submits a form ...
> I have seen something about '*fopen*' , is that the direction I should 
> be going?
> 
> Here is what I am trying to accomplish:
> 
> I am creating a program to keep track of recipes for my wife. I have 
> have page set up where she can put the name of the recipe, the 
> ingredients, and the amounts of each ingredient.
> Then she clicks "Submit"
> 
> I would like a html file with the name of the recipe to be created ie 
> *cookies.html  *with a link to the cookies.html created on another page.
> *
> *I hope this makes sense,  and thank you all for your time...
> 
> - - Kevin
> 


It might sound overkill, but I'd use a database for this. All the
recipes can be stored in a MySQL database, and then you can use a simple
couple of queries to produce the recipe list and the recipe pages
dynamically. This also has the advantage that it's very easy to search
the recipe list when it becomes larger, and if you ever want to change
the layout/presentation of the whole system you won't have to recreate
all the recipe pages.

The DB could have several columns labelled: id, name, ingredients,
method

So, the form page (lets assume it's called add.php) could submit to
itself which then adds the recipe to the DB with a query like:

INSERT INTO recipes(name, ingredients, method) VALUES($name,
$ingredients, $method)

This is only a very simple example which could be extended to use
another table for ingredients for a recipe. Don't forget to sanitise any
input coming from the form with mysql_real_escape_string() for inserting
it into the DB.

The list.php page could just use a simple query like:

SELECT id, name FROM recipes

And then create a link to each recipe in the form: recipe.php?recipe=id
(where id is the numerical value used in the DB) and that would then use
a query like:

SELECT * FROM recipe WHERE id=$recipe

MySQL is available on most hosting that you'll find has support for PHP,
and every Linux distribution I've seen has it too.

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




[PHP] Question about creating php files from a form

2010-05-13 Thread Kevin

Hello All,

I am trying to figure out how to create files when a user submits a form ...
I have seen something about '*fopen*' , is that the direction I should 
be going?


Here is what I am trying to accomplish:

I am creating a program to keep track of recipes for my wife. I have 
have page set up where she can put the name of the recipe, the 
ingredients, and the amounts of each ingredient.

Then she clicks "Submit"

I would like a html file with the name of the recipe to be created ie 
*cookies.html  *with a link to the cookies.html created on another page.

*
*I hope this makes sense,  and thank you all for your time...

- - Kevin

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



RE: [PHP] Append Dom Document

2010-05-13 Thread Alice Wei


Date: Thu, 13 May 2010 18:49:35 -0600
Subject: Re: [PHP] Append Dom Document
From: quickshif...@gmail.com
To: aj...@alumni.iu.edu
CC: php-general@lists.php.net



On Thu, May 13, 2010 at 5:46 PM, Alice Wei  wrote:



Hi,



  I am trying to create a news feed page that loads a number of different feeds 
depending on what options the user selects. For some reason, I could not figure 
out how to get the dom document to "append" the different xml documents that 
get created.




Below is the code, and obviously now every time when I try to have a new item 
selected, then it displays that element's



http://rss.weather.com/rss/national/rss_nwf_rss.xml?cm_ven=NWF&cm_cat=rss&par=NWF_rss";);


break;



case "NFL":

  $xml = ("http://www.nfl.com/rss/rsslanding?searchString=home";);

  break;



default:

exit;

break;

   }

}



$xmlDoc = new DOMDocument();

$xmlDoc->load($xml);



//get and output "" elements

$x=$xmlDoc->getElementsByTagName('item');

for ($i=0; $i<=4; $i++)

  {

  $item_title=$x->item($i)->getElementsByTagName('title')

  ->item(0)->childNodes->item(0)->nodeValue;

  $item_link=$x->item($i)->getElementsByTagName('link')

  ->item(0)->childNodes->item(0)->nodeValue;

  $item_desc=$x->item($i)->getElementsByTagName('description')

  ->item(0)->childNodes->item(0)->nodeValue;



  echo ("" . $item_title . "");

  echo ("");

  echo ($item_desc . "");

  }

you might have an easier time w/ SimpleXML for this task; have a look at the 
examples:
http://us.php.net/manual/en/simplexml.examples-basic.php

the other thing i find strange about this code is the xml parsing assumes a 
similar schema when the source urls are from seemingly totally disparate 
domains, and topic .. id guess it sheer coincidence they have overlapping 
schemas at all.

I am not sure what you mean in your second point, but I can explain the first 
one. I am using PHP to parse RSS feeds, so that is why they all look the same. 
Or, what do you mean here? I checked out your example, but my problem here is 
that I cannot get the XML Dom document to append when I make a new selection. I 
am hoping that it would create a new sub document of some sort beneath the new 
one, instead of overwriting the entire document. 

Am I making sense here?

Alice 
_
The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4

Re: [PHP] Append Dom Document

2010-05-13 Thread Nathan Nobbe
On Thu, May 13, 2010 at 5:46 PM, Alice Wei  wrote:

>
> Hi,
>
>  I am trying to create a news feed page that loads a number of different
> feeds depending on what options the user selects. For some reason, I could
> not figure out how to get the dom document to "append" the different xml
> documents that get created.
>
> Below is the code, and obviously now every time when I try to have a new
> item selected, then it displays that element's
>
> 
> $q=$_GET["q"];
> $q2 = explode(" ",$q);
> $count = count($q2);
>
> for($i=0;$i<$count;$i++) {
>
> //find out which feed was selected
>  switch ($q2[$i]) {
>case "Weather":
>$xml=("
> http://rss.weather.com/rss/national/rss_nwf_rss.xml?cm_ven=NWF&cm_cat=rss&par=NWF_rss
> ");
>break;
>
>case "NFL":
>  $xml = ("http://www.nfl.com/rss/rsslanding?searchString=home";);
>  break;
>
>default:
>exit;
>break;
>   }
> }
>
> $xmlDoc = new DOMDocument();
> $xmlDoc->load($xml);
>
> //get and output "" elements
> $x=$xmlDoc->getElementsByTagName('item');
> for ($i=0; $i<=4; $i++)
>  {
>  $item_title=$x->item($i)->getElementsByTagName('title')
>  ->item(0)->childNodes->item(0)->nodeValue;
>  $item_link=$x->item($i)->getElementsByTagName('link')
>  ->item(0)->childNodes->item(0)->nodeValue;
>  $item_desc=$x->item($i)->getElementsByTagName('description')
>  ->item(0)->childNodes->item(0)->nodeValue;
>
>  echo ("" . $item_title . "");
>  echo ("");
>  echo ($item_desc . "");
>  }
>

you might have an easier time w/ SimpleXML for this task; have a look at the
examples:

http://us.php.net/manual/en/simplexml.examples-basic.php

the other thing i find strange about this code is the xml parsing assumes a
similar schema when the source urls are from seemingly totally disparate
domains, and topic .. id guess it sheer coincidence they have overlapping
schemas at all.

-nathan


[PHP] Append Dom Document

2010-05-13 Thread Alice Wei

Hi, 

  I am trying to create a news feed page that loads a number of different feeds 
depending on what options the user selects. For some reason, I could not figure 
out how to get the dom document to "append" the different xml documents that 
get created. 

Below is the code, and obviously now every time when I try to have a new item 
selected, then it displays that element's 

http://rss.weather.com/rss/national/rss_nwf_rss.xml?cm_ven=NWF&cm_cat=rss&par=NWF_rss";);
break;
  
case "NFL":
  $xml = ("http://www.nfl.com/rss/rsslanding?searchString=home";);
  break;  
   
default:   
exit;
break;
   }
}

$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);

//get and output "" elements
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=4; $i++)
  {
  $item_title=$x->item($i)->getElementsByTagName('title')
  ->item(0)->childNodes->item(0)->nodeValue;
  $item_link=$x->item($i)->getElementsByTagName('link')
  ->item(0)->childNodes->item(0)->nodeValue;
  $item_desc=$x->item($i)->getElementsByTagName('description')
  ->item(0)->childNodes->item(0)->nodeValue;

  echo ("" . $item_title . "");
  echo ("");
  echo ($item_desc . "");
  }

?> 
 

Is there such a function where I could allow my dom document here append and 
not have to create a new one every time when a new selection is made?

Thanks for your help.

Alice
  
_
The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4

Re: [PHP] GD - import a PNG image and make transparant

2010-05-13 Thread Alex Davies
Hi Ash,

Thanks for your suggestion. I think this is where my confusion is. I
understand how to use imagecolorallocatealpha() to for example create a 50%
transparant colour, and apply it to a new rectangle for example.

I dont understand how to "apply" it to a new source image, for example
$src = imagecreatefrompng('test.png');
// Something here (maybe  imagecolorallocatealpha()) to make this
50% transparent- either on its own, or make it 50% transparent as part of a
copy onto a new image

I had thought that imagecopymerge would help me with this, but it seems not.

I'm currently looking through Karl's example to see if I can work it out,
but if anyone can point out a super-simple way of achieving the pseudo-code
above, i'd be very grateful!

Cheers,

Alex

On Thu, May 13, 2010 at 1:34 AM, Ashley Sheridan
wrote:

>  On Thu, 2010-05-13 at 00:12 +0100, Alex Davies wrote:
>
> Hi,
>
> I am trying to import a PNG image from disk, place it on top of a
> transparant image created in GD and output it to the browser. In the case of
> a low opacity setting, I would expect to see the background colour from the
> HTML page.
>
> If I set the opacity to 0, everything works - I end up with a transparant
> image.
>
> However, if I set it for any value >0 (even 1) instead of  a
> very-faint-image the whole thing goes black. As the opacity level goes up
> from 0, the amount of black reduces and the amount of imported image
> increases - but this is not what I want.
>
> I am using this code:
>
>  $src = imagecreatefrompng('test.png');
> $img_width  = imagesx($src);
> $img_height = imagesy($src);
>
> // Create trans image
> $dest = imagecreatetruecolor($img_width, $img_height);
> //imagesavealpha($dest, true); // This has no effect it appears
> $trans_colour = imagecolorallocatealpha($dest, 0, 255, 0, 128);
>
> // Make the background transparent
> imagecolortransparent($dest, $trans_colour);
> //imagefill($dest, 0, 0, $trans_colour); // This does not work
>
> // Merge src on top of dest, with opacity of 1 in this case
> imagecopymerge($dest, $src, 0, 0, 0, 0, $img_width, $img_height, 1);
>
> // Output and free from memory
> header('Content-Type: image/png');
> imagepng($dest);
> ?>
>
> The images that this outputs, at opacity levels 0,1 and 80 on a red and
> green background (screenshots of a HTML page) can be downloaded 
> fromhttp://www.box.net/shared/h9zn4tjgro
>
> Any help appreciated!
>
> Cheers,
>
> Alex
>
>
> How exactly are you setting the opacity for the image? The traditional way
> is to use imagecolorallocatealpha() on the source.
>
>   Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>


-- 
Alex Davies

This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the sender immediately by e-mail and delete this e-mail permanently.


Re: [PHP] GD - import a PNG image and make transparant

2010-05-13 Thread Karl DeSaulniers

Hey tedd,
Sorry bout that.. here you go.

http://designdrumm.com/upload_images_test.zip

Karl


On May 13, 2010, at 9:06 AM, tedd wrote:


At 6:40 PM -0500 5/12/10, Karl DeSaulniers wrote:

Hi Alex,
I have a php file I made just a few months ago.
It takes a gif, jpeg or png of any size and sizes it  
proportionately to a specified size and then outputs a png.
If the image is a transparent png or transparent gif, it will  
still hold the transparency.
This is just a test page and it tested ok for me, but it is my  
first one. I also tested it on PHP 5. Dont know about  
compatibility to older versions.

Knowing that, here you go.

http://designdrumm.com/upload_images_test.php.zip

HTH,

Karl



Bad link.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Karl DeSaulniers
Design Drumm
http://designdrumm.com


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



Re: [PHP] opening a link in a new window

2010-05-13 Thread Ashley Sheridan
On Thu, 2010-05-13 at 17:13 -0400, David Mehler wrote:

> Hello,
> I want to open an external link in a new window, i know i can do this
> with xhtml, but only with the transitional dtd, which i'm not using. I
> was wondering if php could pull this off?
> Thanks.
> Dave.
> 


No. PHP is on the server, not the client-side. If you can't use
something like target="_blank" in your xhtml, then consider using
Javascript. It's not the ideal solution, as it won't work where
scripting is disabled or not available.

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




[PHP] opening a link in a new window

2010-05-13 Thread David Mehler
Hello,
I want to open an external link in a new window, i know i can do this
with xhtml, but only with the transitional dtd, which i'm not using. I
was wondering if php could pull this off?
Thanks.
Dave.

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



Re: [PHP] GD - import a PNG image and make transparant

2010-05-13 Thread tedd

At 6:40 PM -0500 5/12/10, Karl DeSaulniers wrote:

Hi Alex,
I have a php file I made just a few months ago.
It takes a gif, jpeg or png of any size and sizes it proportionately 
to a specified size and then outputs a png.
If the image is a transparent png or transparent gif, it will still 
hold the transparency.
This is just a test page and it tested ok for me, but it is my first 
one. I also tested it on PHP 5. Dont know about compatibility to 
older versions.

Knowing that, here you go.

http://designdrumm.com/upload_images_test.php.zip

HTH,

Karl



Bad link.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] function/class to convert IDN (Puny-Code)?

2010-05-13 Thread tedd

At 4:51 AM +0200 5/13/10, Michelle Konzack wrote:

Hello,

while reading RFC3490 (plus 3454/3491/3492) and before I am  ongoing  to
reinvent the wheel here the question:

Does someone HAVE or know a function/class which
does the IDN conversion "toASCII" and "toUNICODE"?

Note:   The C Source-Code is included in RFC3492 and
can more or less easily converted to PHP.

Thanks, Greetings and nice Day/Evening
Michelle Konzack
Systemadministrator


You might try:

http://josefsson.org/idn.php

I use:

http://mct.verisign-grs.com/index.shtml

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] create tree from arrays

2010-05-13 Thread Richard Quadling
On 13 May 2010 11:42, shahrzad khorrami  wrote:
>
> Dear Richard,
>  we have more than one parentID  with value 0 in main array, your
> code is so good but show me just the children of first parentID 0.
>
> :)
>
> Thanks,
> Shahrzad
>

print_r($Data[0]['children']);

maybe.

-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] create tree from arrays

2010-05-13 Thread shahrzad khorrami
Dear Richard,
 we have more than one parentID  with value 0 in main array, your
code is so good but show me just the children of first parentID 0.

:)

Thanks,
Shahrzad


Re: [PHP] create tree from arrays

2010-05-13 Thread shahrzad khorrami
Thanks Rechard :) I'm testing it... merccc


Re: [PHP] create tree from arrays

2010-05-13 Thread Richard Quadling
On 13 May 2010 11:09, Richard Quadling  wrote:
> On 13 May 2010 09:51, shahrzad khorrami  wrote:
>> hi all,
>>
>> I want to create an array from another array to create json file in my
>> format and pass it to a js libraryok.
>> I just know that I have to use recursive function... but how? it's hard for
>> me to create the new array..
>
> Assuming that nid = 1 / parentID = 0 is the root.
>
>  $Relationships = array();
> foreach($Data as $ID => $Row)
>        {
>        $Relationships[$ID] = $Row['nid'];
>        }
>
> foreach($Data as $ID => &$Row)
>        {
>        if (0 != $Row['parentID'])
>                {
>                $Data[array_search($Row['parentID'], 
> $Relationships)]['children'][] = &$Row;
>                }
>        }
>
> print_r($Data[0]);
> ?>
>
> outputs ...
>
> Array
> (
>    [nid] => 1
>    [parentID] => 0
>    [text] => Dashboard
>    [cls] => x-btn-icon
>    [icon] => lib/extjs/resources/images/default/icon/Dashboard.png
>    [singleClickExpand] => 1
>    [leaf] => 0
>    [id] => Dashboard
>    [children] => Array
>        (
>            [0] => Array
>                (
>                    [nid] => 2
>                    [parentID] => 1
>                    [text] => Dashboard
>                    [cls] => firstExpanded
>                    [icon] => lib/extjs/resources/images/default/tree/s.gif
>                    [singleClickExpand] => 1
>                    [leaf] => 0
>                    [id] =>
>                    [children] => Array
>                        (
>                            [0] => Array
>                                (
>                                    [nid] => 3
>                                    [parentID] => 2
>                                    [text] => Dashboard
>                                    [cls] => x-btn-icon
>                                    [icon] =>
> lib/extjs/resources/images/default/tree/s.gif
>                                    [singleClickExpand] => 1
>                                    [leaf] => 1
>                                    [id] => dashboard
>                                )
>
>                        )
>
>                )
>
>        )
>
> )
>
>
>
> --
> -
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
>

If the array index was the same as nid this would be ...

 &$Row)
{
if (0 != $Row['parentID'])
{
$Data[$Row['parentID']]['children'][] = &$Row;
}
}

print_r($Data[1]);
?>



-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling


Re: [PHP] create tree from arrays

2010-05-13 Thread Richard Quadling
On 13 May 2010 09:51, shahrzad khorrami  wrote:
> hi all,
>
> I want to create an array from another array to create json file in my
> format and pass it to a js libraryok.
> I just know that I have to use recursive function... but how? it's hard for
> me to create the new array..

Assuming that nid = 1 / parentID = 0 is the root.

 $Row)
{
$Relationships[$ID] = $Row['nid'];
}

foreach($Data as $ID => &$Row)
{
if (0 != $Row['parentID'])
{
$Data[array_search($Row['parentID'], 
$Relationships)]['children'][] = &$Row;
}
}

print_r($Data[0]);
?>

outputs ...

Array
(
[nid] => 1
[parentID] => 0
[text] => Dashboard
[cls] => x-btn-icon
[icon] => lib/extjs/resources/images/default/icon/Dashboard.png
[singleClickExpand] => 1
[leaf] => 0
[id] => Dashboard
[children] => Array
(
[0] => Array
(
[nid] => 2
[parentID] => 1
[text] => Dashboard
[cls] => firstExpanded
[icon] => lib/extjs/resources/images/default/tree/s.gif
[singleClickExpand] => 1
[leaf] => 0
[id] =>
[children] => Array
(
[0] => Array
(
[nid] => 3
[parentID] => 2
[text] => Dashboard
[cls] => x-btn-icon
[icon] =>
lib/extjs/resources/images/default/tree/s.gif
[singleClickExpand] => 1
[leaf] => 1
[id] => dashboard
)

)

)

)

)



-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



[PHP] create tree from arrays

2010-05-13 Thread shahrzad khorrami
hi all,

I want to create an array from another array to create json file in my
format and pass it to a js libraryok.
I just know that I have to use recursive function... but how? it's hard for
me to create the new array..

main array:

Array
(
[0] => Array
(
[nid] => 1
[parentID] => 0
[text] => Dashboard
[cls] => x-btn-icon
[icon] => lib/extjs/resources/images/default/icon/Dashboard.png
[singleClickExpand] => 1
[leaf] => 0
[id] => Dashboard
)

[1] => Array
(
[nid] => 2
[parentID] => 1
[text] => Dashboard
[cls] => firstExpanded
[icon] => lib/extjs/resources/images/default/tree/s.gif
[singleClickExpand] => 1
[leaf] => 0
[id] =>
)

[2] => Array
(
[nid] => 3
[parentID] => 2
[text] => Dashboard
[cls] => x-btn-icon
[icon] => lib/extjs/resources/images/default/tree/s.gif
[singleClickExpand] => 1
[leaf] => 1
[id] => dashboard
)
...


-- The array I want to create: 

[0] => Array
(
[nid] => 1
[parentID] => 0
[text] => Dashboard
[cls] => x-btn-icon
[icon] => lib/extjs/resources/images/default/icon/Dashboard.png
[singleClickExpand] => 1
[leaf] => 0
[id] => Dashboard
[children] => Array(
 [0] => Array
(
[nid] => 2
[parentID] => 1
[text] => Dashboard
[cls] => firstExpanded
[icon] =>
lib/extjs/resources/images/default/tree/s.gif
[singleClickExpand] => 1
[leaf] => 0
[id] =>
[children] => Array(
[0] => Array
(
  [nid] => 3
  [parentID] => 2
  [text] => Dashboard
  [cls] => x-btn-icon
  [icon] =>
lib/extjs/resources/images/default/tree/s.gif
  [singleClickExpand] =>
1
  [leaf] => 1
  [id] => dashboard
  )
)
)
)
)

.
wow!
it means that by nid and parentID, I'll notice where I must add children
item to array...

Thanks,
Shahrzad


RE: [PHP] Parse question

2010-05-13 Thread Lawrance Shepstone
-Original Message-
From: Ron Piggott [mailto:ron.pigg...@actsministries.org] 
Sent: 13 May 2010 06:34 AM
To: PHP General
Subject: [PHP] Parse question


If $message_body contains:

$message_body="You are subscribed using u...@domain. To update";

How do I capture just the e-mail address?

Ron

__

Regular Expressions ... They're great at this sort of thing!

I'd suggest starting here:

http://www.regular-expressions.info/email.html

Then take a look at the PHP regular expression manual:

http://www.php.net/manual/en/book.pcre.php

Have fun!
Lawrance


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



Re: [PHP] Parse question

2010-05-13 Thread Cemal Eker
Check this out.  http://www.regular-expressions.info/email.html
---
“Talk is cheap. Show me the code” - Linus Torvalds


On Thu, May 13, 2010 at 7:34 AM, Ron Piggott  wrote:

>
> If $message_body contains:
>
> $message_body="You are subscribed using u...@domain. To update";
>
> How do I capture just the e-mail address?
>
> Ron
>
>


[PHP] Parse question

2010-05-13 Thread Ron Piggott

If $message_body contains:

$message_body="You are subscribed using u...@domain. To update";

How do I capture just the e-mail address?

Ron



RE: [PHP] stristr query trouble

2010-05-13 Thread Lawrance Shepstone
On 13 May 2010 10:08, Lawrance Shepstone  wrote:
> -Original Message-
> From: Ron Piggott [mailto:ron@actsministries.org]
> Sent: 13 May 2010 06:02 AM
> To: PHP General
> Subject: [PHP] stristr query trouble
>
> I am not understanding why 'true' isn't the result of this syntax because
> $subjects equals:
>
> $subjects = "Delivery Status Notification(Failure)";
>
> Here is my syntax:
>
> if ( stristr( $subjects, "Delivery Status Notifcation(Failure)" ) ) {
> $TIRSFlag = true;
> echo "true";
> }
>
> _
>
> You have misspelled 'Notification' in your comparison ...
>
> You should probably use Regular Expressions for this kind of thing.
>

Regexes are best used when what you need to match is dynamic or in a
dynamic string. When you know what the output will be and can match
it, the str* functions are much better as they are much more
efficient.

Regards
Peter



Agreed ;-)


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



Re: [PHP] stristr query trouble

2010-05-13 Thread Peter Lind
On 13 May 2010 10:08, Lawrance Shepstone  wrote:
> -Original Message-
> From: Ron Piggott [mailto:ron@actsministries.org]
> Sent: 13 May 2010 06:02 AM
> To: PHP General
> Subject: [PHP] stristr query trouble
>
> I am not understanding why 'true' isn't the result of this syntax because
> $subjects equals:
>
> $subjects = "Delivery Status Notification(Failure)";
>
> Here is my syntax:
>
> if ( stristr( $subjects, "Delivery Status Notifcation(Failure)" ) ) {
> $TIRSFlag = true;
> echo "true";
> }
>
> _
>
> You have misspelled 'Notification' in your comparison ...
>
> You should probably use Regular Expressions for this kind of thing.
>

Regexes are best used when what you need to match is dynamic or in a
dynamic string. When you know what the output will be and can match
it, the str* functions are much better as they are much more
efficient.

Regards
Peter

-- 

WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51


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



Re: [PHP] stristr query trouble

2010-05-13 Thread Warren Windvogel

Ron Piggott wrote:

$subjects = "Delivery Status Notification(Failure)";

Here is my syntax:

if ( stristr( $subjects, "Delivery Status Notifcation(Failure)" ) ) {
  
Notification is misspelled. Next time copy and paste the comparison 
string or use regular expressions to be more safe.


Kind regards
Warren

--
Developer
The University of the Witwatersrand 
Email: warren.windvo...@wits.ac.za

Gmail: wwindvo...@gmail.com
MSN: wwindvo...@hotmail.com
Skype: wwindvogel
Tel: +27 11 717 7184
Cell: +27 73 264 6700
Fax2Email: 0862950483


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



RE: [PHP] stristr query trouble

2010-05-13 Thread Lawrance Shepstone
-Original Message-
From: Ron Piggott [mailto:ron@actsministries.org] 
Sent: 13 May 2010 06:02 AM
To: PHP General
Subject: [PHP] stristr query trouble

I am not understanding why 'true' isn't the result of this syntax because
$subjects equals:

$subjects = "Delivery Status Notification(Failure)";

Here is my syntax:

if ( stristr( $subjects, "Delivery Status Notifcation(Failure)" ) ) {
$TIRSFlag = true; 
echo "true";
}

_

You have misspelled 'Notification' in your comparison ...

You should probably use Regular Expressions for this kind of thing.

Best of luck,
Lawrance


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



[PHP] stristr query trouble

2010-05-13 Thread Ron Piggott


I am not understanding why 'true' isn't the result of this syntax because
$subjects equals:

$subjects = "Delivery Status Notification(Failure)";

Here is my syntax:

if ( stristr( $subjects, "Delivery Status Notifcation(Failure)" ) ) {
$TIRSFlag = true; 
echo "true";
}