Re: [PHP] parsing select multiple=multiple

2013-02-21 Thread Jim Giner




I *have* heard claims that something like this is preferrable, though:

if (FALSE === $variable)

I believe I read a comment somewhere once that writing your IF 
statements that way helped to trigger an error message when the coder 
forgot to use the double equal sign (==) in the statement.  I haven't 
adopted it yet, but I think that's the sole reason for it.  Basically 
you can't make an assignment (=) to a constant or some non-variable target.


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



Re: [PHP] parsing select multiple=multiple

2013-02-21 Thread tamouse mailing lists
On Thu, Feb 21, 2013 at 8:46 AM, Jim Giner jim.gi...@albanyhandball.com wrote:


 I *have* heard claims that something like this is preferrable, though:

 if (FALSE === $variable)

 I believe I read a comment somewhere once that writing your IF statements
 that way helped to trigger an error message when the coder forgot to use the
 double equal sign (==) in the statement.  I haven't adopted it yet, but I
 think that's the sole reason for it.  Basically you can't make an assignment
 (=) to a constant or some non-variable target.

That sounds like a reasonable explanation to me.

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



Re: [PHP] parsing select multiple=multiple

2013-02-20 Thread Tedd Sperling
On Feb 18, 2013, at 7:54 PM, John Taylor-Johnston 
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:

 I am capable with select name=DPRpriority. (I suppose I did it correctly? 
 :p )
 But I haven't the first clue how to parse a select multiple and multiply 
 select name=DPRtype.
 Would anyone give me a couple of clues please? :)
 Thanks,
 John

John:

A clue? How about an example? 

See here:

http://sperling.com/php/select/index.php

Cheers,

tedd

_
t...@sperling.com
http://sperling.com



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



Re: [PHP] parsing select multiple=multiple

2013-02-20 Thread Jim Giner

On 2/20/2013 11:41 AM, Tedd Sperling wrote:

On Feb 18, 2013, at 7:54 PM, John Taylor-Johnston 
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:


I am capable with select name=DPRpriority. (I suppose I did it correctly? 
:p )
But I haven't the first clue how to parse a select multiple and multiply select 
name=DPRtype.
Would anyone give me a couple of clues please? :)
Thanks,
John


John:

A clue? How about an example?

See here:

http://sperling.com/php/select/index.php

Cheers,

tedd

_
t...@sperling.com
http://sperling.com



Try googling it.  It's out there.

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



Re: [PHP] parsing select multiple=multiple

2013-02-20 Thread tamouse mailing lists
On Tue, Feb 19, 2013 at 1:02 PM, John Taylor-Johnston
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:

 tamouse mailing lists wrote:

 I hate arrays. :D

 Here's a small snippet showing how it works, I hope:

 foreach ($DPRpriority as $item = $value) {
echo li .$item.: .$value['name']. selected:
 .$value['selected']. /li\n;
 }

 Question 1: when did we have to add [] to a input name to turn it into an
 array?

 input type=checkbox name=DPRlocationdetails[] value=Unknown

 According to phpinfo() it still comes out as $_POST['DPRlocationdetails']
 without [].

 Are the [] necessary?

[] are necessary when you want to return multiple values for a form
field, or collection of form fields such as checkbox. AFAIK, this has
always been the case with PHP. See
https://gist.github.com/tamouse/5002728

 --
 Question 2:
 I was looking at some code in the Manual, where someone used isset and
 is_array.

 How necessary is if(isset($_POST['DPRlocationdetails']))

 and then to use: if(is_array($_POST['DPRlocationdetails']))

 That seems like over kill?

It's more defensive, in the case where someone may be by-passing your
form to send things in.

 --
 Question 3:

 My code works, perfectly.

Then there must be no questions. :)

 In this case, I decided to attack some check-boxes
 first. The resulting function will work for select multiple too..

 Does anyone see me doing something wrong in my code below?

 My questions are:

 Is this the only way to pass Unknown, Family Home or Apartment into
 the function?

 Is this correct?

  if ($_POST['DPRlocationdetails'] == Unknown)

 Somebody once told me I had to do it this way?

  if (Unknown == $_POST['DPRlocationdetails'])

In this scenario, these are equivalent. There is no preference of one
over the other.

I *have* heard claims that something like this is preferrable, though:

if (FALSE === $variable)

But I think that may have been due to some misunderstanding of
precedences in the following sort of scenario:

if (FALSE === ($result = some_function())

where if done this way:

if ($result = some_function() === FALSE)

was giving them bad results.

 John

 snip---

 form action=foo.php id=DPRform method=postinput value=Update
 type=submit
 input type=checkbox name=DPRlocationdetails[] value=Unknown ?php
 filter_value($_POST['DPRlocationdetails'],Unknown); ? Unknown
 input type=checkbox name=DPRlocationdetails[] value=Family Home ?php
 filter_value($_POST['DPRlocationdetails'],Family Home); ? Family Home
 input type=checkbox name=DPRlocationdetails[] value=Apartment ?php
 filter_value($_POST['DPRlocationdetails'],Apartment); ? Apartment
 /form

 ?php
 function filter_value($tofilter,$tofind) {
 foreach($tofilter as $value){
 if ($value == $tofind) echo checked;
 }
 }
 ?



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



Re: [PHP] parsing select multiple=multiple

2013-02-19 Thread John Taylor-Johnston


tamouse mailing lists wrote:

I hate arrays. :D

Here's a small snippet showing how it works, I hope:

foreach ($DPRpriority as $item = $value) {
   echo li .$item.: .$value['name']. selected:
.$value['selected']. /li\n;
}

Question 1: when did we have to add [] to a input name to turn it into 
an array?


input type=checkbox name=DPRlocationdetails[] value=Unknown

According to phpinfo() it still comes out as 
$_POST['DPRlocationdetails'] without [].


Are the [] necessary?
--
Question 2:
I was looking at some code in the Manual, where someone used isset and 
is_array.


How necessary is if(isset($_POST['DPRlocationdetails']))

and then to use: if(is_array($_POST['DPRlocationdetails']))

That seems like over kill?
--
Question 3:

My code works, perfectly. In this case, I decided to attack some 
check-boxes first. The resulting function will work for select 
multiple too..


Does anyone see me doing something wrong in my code below?

My questions are:

Is this the only way to pass Unknown, Family Home or Apartment 
into the function?


Is this correct?

 if ($_POST['DPRlocationdetails'] == Unknown)

Somebody once told me I had to do it this way?

 if (Unknown == $_POST['DPRlocationdetails'])

John

snip---

form action=foo.php id=DPRform method=postinput value=Update 
type=submit
input type=checkbox name=DPRlocationdetails[] value=Unknown ?php 
filter_value($_POST['DPRlocationdetails'],Unknown); ? Unknown
input type=checkbox name=DPRlocationdetails[] value=Family Home 
?php filter_value($_POST['DPRlocationdetails'],Family Home); ? 
Family Home
input type=checkbox name=DPRlocationdetails[] value=Apartment 
?php filter_value($_POST['DPRlocationdetails'],Apartment); ? Apartment

/form

?php
function filter_value($tofilter,$tofind) {
foreach($tofilter as $value){
if ($value == $tofind) echo checked;
}
}
?



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



Re: [PHP] parsing select multiple=multiple

2013-02-19 Thread Jim Giner

On 2/19/2013 2:02 PM, John Taylor-Johnston wrote:


tamouse mailing lists wrote:

I hate arrays. :D

Here's a small snippet showing how it works, I hope:

foreach ($DPRpriority as $item = $value) {
   echo li .$item.: .$value['name']. selected:
.$value['selected']. /li\n;
}


Question 1: when did we have to add [] to a input name to turn it into
an array?

input type=checkbox name=DPRlocationdetails[] value=Unknown

According to phpinfo() it still comes out as
$_POST['DPRlocationdetails'] without [].

Are the [] necessary?
--
Question 2:
I was looking at some code in the Manual, where someone used isset and
is_array.

How necessary is if(isset($_POST['DPRlocationdetails']))

and then to use: if(is_array($_POST['DPRlocationdetails']))

That seems like over kill?
--
Question 3:

My code works, perfectly. In this case, I decided to attack some
check-boxes first. The resulting function will work for select
multiple too..

Does anyone see me doing something wrong in my code below?

My questions are:

Is this the only way to pass Unknown, Family Home or Apartment
into the function?

Is this correct?

 if ($_POST['DPRlocationdetails'] == Unknown)

Somebody once told me I had to do it this way?

 if (Unknown == $_POST['DPRlocationdetails'])

John

snip---

form action=foo.php id=DPRform method=postinput value=Update
type=submit
input type=checkbox name=DPRlocationdetails[] value=Unknown ?php
filter_value($_POST['DPRlocationdetails'],Unknown); ? Unknown
input type=checkbox name=DPRlocationdetails[] value=Family Home
?php filter_value($_POST['DPRlocationdetails'],Family Home); ?
Family Home
input type=checkbox name=DPRlocationdetails[] value=Apartment
?php filter_value($_POST['DPRlocationdetails'],Apartment); ? Apartment
/form

?php
function filter_value($tofilter,$tofind) {
foreach($tofilter as $value){
 if ($value == $tofind) echo checked;
 }
}
?


The [] are necessary if there are going to be multiple occurrences of an 
input with the same name, hence the [] to allow your php script to 
extract all of the occurrences.


Using isset and is_array comes in handy to help you handle the incoming 
var properly.  If it IS set, you then have to check if there is only one 
value (hence a string) or if there are multiple values (an array).


#3 - no idea what you are asking.   

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



[PHP] parsing select multiple=multiple

2013-02-18 Thread John Taylor-Johnston
I am capable with select name=DPRpriority. (I suppose I did it 
correctly? :p )
But I haven't the first clue how to parse a select multiple and 
multiply select name=DPRtype.

Would anyone give me a couple of clues please? :)
Thanks,
John

   Priority:
   select name=DPRpriority form=DPRform
 option value=1 ?php if ($_POST[DPRpriority] == 1) 
{echo selected;} ?1/option
 option value=2 ?php if ($_POST[DPRpriority] == 2) 
{echo selected;} ?2/option
 option value=3 ?php if ($_POST[DPRpriority] == 3) 
{echo selected;} ?3/option

 option value=4 ?php
 if (empty($_POST[DPRpriority])) {echo selected;}
 if ($_POST[DPRpriority] == 4) {echo selected;} 
?4/option

   /select


   select multiple=multiple name=DPRtype form=DPRform
 option value=1. Crimes Against Persons1. Crimes 
Against Persons/option

 option value=2. Disturbances2. Disturbances/option
 option value=3. Assistance / Medical3. Assistance / 
Medical/option
 option value=4. Crimes Against Property4. Crimes 
Against Property/option
 option value=5. Accidents / Traffic Problems5. 
Accidents / Traffic Problems/option
 option value=6. Suspicious Circumstances6. Suspicious 
Circumstances/option
 option value=7. Morality / Drugs7. Morality / 
Drugs/option
 option value=8. Miscellaneous Service8. Miscellaneous 
Service/option

 option value=9. Alarms9. Alarms/option
   /select


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



Re: [PHP] parsing select multiple=multiple

2013-02-18 Thread tamouse mailing lists
On Mon, Feb 18, 2013 at 6:54 PM, John Taylor-Johnston
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:
 I am capable with select name=DPRpriority. (I suppose I did it
 correctly? :p )
 But I haven't the first clue how to parse a select multiple and multiply
 select name=DPRtype.
 Would anyone give me a couple of clues please? :)
 Thanks,
 John

Priority:
select name=DPRpriority form=DPRform
  option value=1 ?php if ($_POST[DPRpriority] == 1) {echo
 selected;} ?1/option
  option value=2 ?php if ($_POST[DPRpriority] == 2) {echo
 selected;} ?2/option
  option value=3 ?php if ($_POST[DPRpriority] == 3) {echo
 selected;} ?3/option
  option value=4 ?php
  if (empty($_POST[DPRpriority])) {echo selected;}
  if ($_POST[DPRpriority] == 4) {echo selected;}
 ?4/option
/select


select multiple=multiple name=DPRtype form=DPRform
  option value=1. Crimes Against Persons1. Crimes Against
 Persons/option
  option value=2. Disturbances2. Disturbances/option
  option value=3. Assistance / Medical3. Assistance /
 Medical/option
  option value=4. Crimes Against Property4. Crimes Against
 Property/option
  option value=5. Accidents / Traffic Problems5. Accidents /
 Traffic Problems/option
  option value=6. Suspicious Circumstances6. Suspicious
 Circumstances/option
  option value=7. Morality / Drugs7. Morality /
 Drugs/option
  option value=8. Miscellaneous Service8. Miscellaneous
 Service/option
  option value=9. Alarms9. Alarms/option
/select


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


Do test this, but I think all that's required is you make the name an array:

select name=DPRpriority[] form=DPRform

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



Re: [PHP] parsing select multiple=multiple

2013-02-18 Thread John Taylor-Johnston



 select multiple=multiple name=DPRtype form=DPRform
 option value=1. Crimes Against Persons1. Crimes Against
Persons/option
 option value=2. Disturbances2. Disturbances/option
 option value=3. Assistance / Medical3. Assistance /
Medical/option
 option value=4. Crimes Against Property4. Crimes Against
Property/option
 option value=5. Accidents / Traffic Problems5. Accidents /
Traffic Problems/option
 option value=6. Suspicious Circumstances6. Suspicious
Circumstances/option
 option value=7. Morality / Drugs7. Morality /
Drugs/option
 option value=8. Miscellaneous Service8. Miscellaneous
Service/option
 option value=9. Alarms9. Alarms/option
   /select





Do test this, but I think all that's required is you make the name an array:

select name=DPRpriority[] form=DPRform
  

Something like this?

if $DPRpriority[0] == 7. Morality / Drugs { echo selected; }

I hate arrays. :D

http://php.net/manual/en/language.types.array.php

?php
$DPRpriority[]  = array(
   1= a,
   1  = b,
   1.5  = c,
   true = d,
);
var_dump($array);
?



Re: [PHP] parsing select multiple=multiple

2013-02-18 Thread David Robley
tamouse mailing lists wrote:

 On Mon, Feb 18, 2013 at 6:54 PM, John Taylor-Johnston
 john.taylor-johns...@cegepsherbrooke.qc.ca wrote:
 I am capable with select name=DPRpriority. (I suppose I did it
 correctly? :p )
 But I haven't the first clue how to parse a select multiple and
 multiply select name=DPRtype.
 Would anyone give me a couple of clues please? :)
 Thanks,
 John

Priority:
select name=DPRpriority form=DPRform
  option value=1 ?php if ($_POST[DPRpriority] == 1)
  {echo
 selected;} ?1/option
  option value=2 ?php if ($_POST[DPRpriority] == 2)
  {echo
 selected;} ?2/option
  option value=3 ?php if ($_POST[DPRpriority] == 3)
  {echo
 selected;} ?3/option
  option value=4 ?php
  if (empty($_POST[DPRpriority])) {echo selected;}
  if ($_POST[DPRpriority] == 4) {echo selected;}
 ?4/option
/select


select multiple=multiple name=DPRtype form=DPRform
  option value=1. Crimes Against Persons1. Crimes Against
 Persons/option
  option value=2. Disturbances2. Disturbances/option
  option value=3. Assistance / Medical3. Assistance /
 Medical/option
  option value=4. Crimes Against Property4. Crimes Against
 Property/option
  option value=5. Accidents / Traffic Problems5. Accidents
  /
 Traffic Problems/option
  option value=6. Suspicious Circumstances6. Suspicious
 Circumstances/option
  option value=7. Morality / Drugs7. Morality /
 Drugs/option
  option value=8. Miscellaneous Service8. Miscellaneous
 Service/option
  option value=9. Alarms9. Alarms/option
/select


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

 
 Do test this, but I think all that's required is you make the name an
 array:
 
 select name=DPRpriority[] form=DPRform

More info at http://www.php.net/manual/en/language.variables.external.php 
(search for multiple) and 
http://www.php.net/manual/en/faq.html.php#faq.html.select-multiple

-- 
Cheers
David Robley

Know what I hate? I hate rhetorical questions!


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



Re: [PHP] parsing select multiple=multiple

2013-02-18 Thread tamouse mailing lists
On Mon, Feb 18, 2013 at 7:28 PM, John Taylor-Johnston
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:

  select multiple=multiple name=DPRtype form=DPRform
  option value=1. Crimes Against Persons1. Crimes Against
 Persons/option
  option value=2. Disturbances2. Disturbances/option
  option value=3. Assistance / Medical3. Assistance /
 Medical/option
  option value=4. Crimes Against Property4. Crimes Against
 Property/option
  option value=5. Accidents / Traffic Problems5. Accidents
 /
 Traffic Problems/option
  option value=6. Suspicious Circumstances6. Suspicious
 Circumstances/option
  option value=7. Morality / Drugs7. Morality /
 Drugs/option
  option value=8. Miscellaneous Service8. Miscellaneous
 Service/option
  option value=9. Alarms9. Alarms/option
/select





 Do test this, but I think all that's required is you make the name an
 array:

 select name=DPRpriority[] form=DPRform


 Something like this?

 if $DPRpriority[0] == 7. Morality / Drugs { echo selected; }

 I hate arrays. :D

 http://php.net/manual/en/language.types.array.php

 ?php
 $DPRpriority[]  = array(
1= a,
1  = b,
1.5  = c,
true = d,
 );
 var_dump($array);
 ?


Not exactly that -- I think I goofed up your variable names.
$DPRpriority is the set of values that can be selected, and DPRType
are the values returned from the form.

Here's a small snippet showing how it works, I hope:

?php

// Initial value for demo
$DPRpriority = array(array('name' = Crimes Against Persons,
'selected' = false),
 array('name' = Disturbances, 'selected' = false),
 array('name' = Assistance / Medical, 'selected' = 
false),
 array('name' = Crimes Against Property, 'selected' = 
false),
 array('name' = Accidents / Traffic Problems, 'selected' 
= false),
 array('name' = Suspicious Circumstances, 'selected' = 
false),
 array('name' = Morality / Drugs, 'selected' = false),
 array('name' = Miscellaneous Service, 'selected' = 
false),
 array('name' =Alarms, 'selected' = false));

echo h1Initial value of DPRpriority:/h1ul\n;
foreach ($DPRpriority as $item = $value) {
  echo li .$item.: .$value['name']. selected:
.$value['selected']. /li\n;
}
echo /ul\n;

if (count($_POST)  0) {
  // something was posted:
  echo h1\$_POST:/h1precode\n;
  var_dump($_POST);
  echo /code/pre\n;

  echo h2Items selected:/h2ul\n;
  foreach ($_POST['DPRType'] as $item) {
$DPRpriority[$item]['selected'] = true;
echo li.$item.: .$DPRpriority[$item]['name']./li\n;
  }
  echo /ul\n;

  echo h1Final value of DPRpriority:/h1ul\n;
  foreach ($DPRpriority as $item = $value) {
echo li .$item.: .$value['name']. selected:
.$value['selected']. /li\n;
  }
  echo /ul\n;
}

?

form method=post

select name=DPRType[] id=DPRType[] multiple onchange=
size=?php echo count($DPRpriority) ?
  ?php foreach ($DPRpriority as $index = $value) { ?
option value=?php echo $index; ??php if ($value['selected'])
{echo ' selected=selected';} ??php echo
$value['name'];?/option
 ?php } ?
/select

input type=submit name=submit value=submit /

/form


(gist link: https://gist.github.com/tamouse/4982630 )

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



Re: [PHP] Parsing the From field

2011-11-20 Thread Geoff Shang

On Sat, 19 Nov 2011, Ron Piggott wrote:


Also the formatting of the from field changes in various e-mail programs:

From: Ron Piggott ron.pigg...@actsministries.org
From: Ron Piggott ron.pigg...@actsministries.org
From: ron.pigg...@actsministries.org
From: ron.pigg...@actsministries.org


I've also seen:

Piggott, Ron ron.pigg...@actsministries.org

And that's before you get to people who only use their first name and 
people who use some kind of alias.


I think you did well to abandon this.

Geoff.


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



[PHP] Parsing the From field

2011-11-19 Thread Ron Piggott

I am unsure of how to parse first name, last name and e-mail address from the 
'From:' field of an e-mail.

What I am struggling with is if the name has more than two words 
- Such as the last name being multiple words
- A name a business or department is given instead of a personal name
- If the person has included their middle name, middle initial or degrees 
(“Dr.”)
- If last name has multiple words

Also the formatting of the from field changes in various e-mail programs:

From: Ron Piggott ron.pigg...@actsministries.org
From: Ron Piggott ron.pigg...@actsministries.org
From: ron.pigg...@actsministries.org
From: ron.pigg...@actsministries.org

If there is more than 2 words for the name I would like them to be assigned to 
the last name.

Ron


Ron Piggott



www.TheVerseOfTheDay.info 


Re: [PHP] Parsing the From field

2011-11-19 Thread Alain Williams
On Sat, Nov 19, 2011 at 11:23:59AM -0500, Ron Piggott wrote:
 
 I am unsure of how to parse first name, last name and e-mail address from the 
 'From:' field of an e-mail.
 
 What I am struggling with is if the name has more than two words 
 - Such as the last name being multiple words
 - A name a business or department is given instead of a personal name
 - If the person has included their middle name, middle initial or degrees 
 (“Dr.”)
 - If last name has multiple words
 
 Also the formatting of the from field changes in various e-mail programs:
 
 From: Ron Piggott ron.pigg...@actsministries.org
 From: Ron Piggott ron.pigg...@actsministries.org
 From: ron.pigg...@actsministries.org
 From: ron.pigg...@actsministries.org
 
 If there is more than 2 words for the name I would like them to be assigned 
 to the last name.

You can make no such assumption, different people/companies/... do it in 
different ways.
If you really want to have fun look at the different 'norms' from different 
countries.

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
http://www.phcomp.co.uk/contact.php
#include std_disclaimer.h

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



Re: [PHP] Parsing the From field

2011-11-19 Thread Ron Piggott


My web site is used by people from approximately of 90 countries.

- I will use just name instead of first name / last name.
- e-mail address




Ron Piggott



www.TheVerseOfTheDay.info

-Original Message- 
From: Alain Williams

Sent: Saturday, November 19, 2011 11:29 AM
To: Ron Piggott
Cc: php-general@lists.php.net
Subject: Re: [PHP] Parsing the From field

On Sat, Nov 19, 2011 at 11:23:59AM -0500, Ron Piggott wrote:


I am unsure of how to parse first name, last name and e-mail address from 
the 'From:' field of an e-mail.


What I am struggling with is if the name has more than two words
- Such as the last name being multiple words
- A name a business or department is given instead of a personal name
- If the person has included their middle name, middle initial or degrees 
(“Dr.”)

- If last name has multiple words

Also the formatting of the from field changes in various e-mail programs:

From: Ron Piggott ron.pigg...@actsministries.org
From: Ron Piggott ron.pigg...@actsministries.org
From: ron.pigg...@actsministries.org
From: ron.pigg...@actsministries.org

If there is more than 2 words for the name I would like them to be 
assigned to the last name.


You can make no such assumption, different people/companies/... do it in 
different ways.
If you really want to have fun look at the different 'norms' from different 
countries.


--
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
Lecturer.

+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
http://www.phcomp.co.uk/contact.php
#include std_disclaimer.h 



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



Re: [PHP] Parsing the From field

2011-11-19 Thread Al



On 11/19/2011 11:29 AM, Alain Williams wrote:

On Sat, Nov 19, 2011 at 11:23:59AM -0500, Ron Piggott wrote:


I am unsure of how to parse first name, last name and e-mail address from the 
'From:' field of an e-mail.

What I am struggling with is if the name has more than two words
- Such as the last name being multiple words
- A name a business or department is given instead of a personal name
- If the person has included their middle name, middle initial or degrees 
(“Dr.�)
- If last name has multiple words

Also the formatting of the from field changes in various e-mail programs:

From: Ron Piggottron.pigg...@actsministries.org
From: Ron Piggottron.pigg...@actsministries.org
From: ron.pigg...@actsministries.org
From:ron.pigg...@actsministries.org

If there is more than 2 words for the name I would like them to be assigned to 
the last name.


You can make no such assumption, different people/companies/... do it in 
different ways.
If you really want to have fun look at the different 'norms' from different 
countries.



Perhaps, Ron's email are constrained so there is a finite syntax. e.g., only to 
actsministries.org


Ron: I'd suggest your best approach is to use preg_match()
There are several examples on the net, try Google php preg_match email address



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



[PHP] Parsing a simple sql string in php

2011-05-06 Thread Ashley Sheridan
Hiya, has anyone had any experience with parsing a string of sql to break it 
down into its component parts? At the moment I'm using several regex's to parse 
a string, which works, but I'm sure there's a more elegant solution.

The general idea is to produce a nice looking page giving details of updated 
fields and values.

I'm only concerned with update statements really, and the queries are very 
simple, operating on one table at a time, with no sub queries or selects.

Thanks in advance if anyone is able to suggest anything!
Thanks
Ash


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



Re: [PHP] Parsing a simple sql string in php

2011-05-06 Thread Stuart Dallas
On Friday, 6 May 2011 at 10:05, Ashley Sheridan wrote:
Hiya, has anyone had any experience with parsing a string of sql to break it 
down into its component parts? At the moment I'm using several regex's to parse 
a string, which works, but I'm sure there's a more elegant solution.
 
 The general idea is to produce a nice looking page giving details of updated 
 fields and values.
 
 I'm only concerned with update statements really, and the queries are very 
 simple, operating on one table at a time, with no sub queries or selects.
 
 Thanks in advance if anyone is able to suggest anything!

I don't have any experience doing it with SQL, but I have written several 
parsers in my time, and I'd strongly recommend against using regexes to do it.

The usual way to approach this problem is to tokenise the input, then take each 
token at a time and branch where there are several options for what comes next. 
As you go along, build up a data structure that represents the data you need.

Alternatively you could ask Google...

http://www.phpclasses.org/package/4916-PHP-Build-a-tree-to-represent-an-SQL-query.html
http://code.google.com/p/php-sqlparser/
and more: http://jmp.li/fmy

-Stuart

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






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



Re: [PHP] Parsing a simple sql string in php

2011-05-06 Thread Ken Guest
On Fri, May 6, 2011 at 10:05 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 Hiya, has anyone had any experience with parsing a string of sql to break it 
 down into its component parts? At the moment I'm using several regex's to 
 parse a string, which works, but I'm sure there's a more elegant solution.

 The general idea is to produce a nice looking page giving details of updated 
 fields and values.

 I'm only concerned with update statements really, and the queries are very 
 simple, operating on one table at a time, with no sub queries or selects.

 Thanks in advance if anyone is able to suggest anything!

I'd suggest at least taking a look at pear's sql parser package -
using it might save you some headaches ;)

http://pear.php.net/package/SQL_Parser


 Thanks
 Ash


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





-- 
http://blogs.linux.ie/kenguest/

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



Re: [PHP] Parsing a simple sql string in php

2011-05-06 Thread Ashley Sheridan
Ken Guest k...@linux.ie wrote:

On Fri, May 6, 2011 at 10:05 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 Hiya, has anyone had any experience with parsing a string of sql to
break it down into its component parts? At the moment I'm using several
regex's to parse a string, which works, but I'm sure there's a more
elegant solution.

 The general idea is to produce a nice looking page giving details of
updated fields and values.

 I'm only concerned with update statements really, and the queries are
very simple, operating on one table at a time, with no sub queries or
selects.

 Thanks in advance if anyone is able to suggest anything!

I'd suggest at least taking a look at pear's sql parser package -
using it might save you some headaches ;)

http://pear.php.net/package/SQL_Parser


 Thanks
 Ash


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





--
http://blogs.linux.ie/kenguest/

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

I had seen this but didn't see much in the way of documentation (i only spent 5 
mins looking though) and I've tended to steer away from pear after warnings 
from this very list!

I solved the issue in the end with regex's. As the queries were generally 
fairly basic, it wasn't too hard to write the expressions for them, and so far 
its working well for my needs. I was just asking here to see if anyone had any 
experience with something, not to see if they could phrase the Google search in 
a different way. Thanks though to all who replied.

Thanks
Ash
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

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



[PHP] Parsing a phrase

2010-12-12 Thread Rick Dwyer

Hello all.

I have a page where the user can enter a search phrase and upon  
submitting, the search phrase is queried in MySQL.


However, I need to modify is so each word in the phrase is searched  
for... not just the exact phrase.


So, big blue hat will return results like:

A big hat - blue in color
Hat - blue, big

SQL would look like 

WHERE (item_description like %big% and item_description like %blue 
%  and item_description like %hat% )


So, via PHP, what is the best way to extract each word from the search  
phrase to it's own variable so I can place them dynamically into the  
SQL statement.


Thanks,


 --Rick



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



[PHP] Parsing JSON; back-slash problem

2009-12-15 Thread Andrew Burgess
This seems like a pretty basic question, but it has me stumped.

Here's my scenario: I'm using Douglas Crockford's JSON2.js to parse an
object in JavaScript, which I then pass to a PHP script to store in a
file. I use JSON.stringify() on the object, which logs to the console
as this:

{employees:{data:{John:{fname:John,lname:Doe,city:Toronto,country:Canada

Then I use the jQuery POST function to send it to a PHP script. Before
doing anything with it in PHP, I log the received value to the
console, and this is what I get:

{\employees\:{\data\:{\John\:{\fname\:\John\,\lname\:\Doe\,\city\:\Toronto\,\country\:\Canada\

The problem is, when I call the script to retrieve this data from a
file, JSON.parse can't parse it because of the back-slashes. I'm
pretty sure my problem is on the PHP side (since it's fine coming out
of JS); what do I need to do to fix this? is a preg_replace enough?

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



Re: [PHP] Parsing JSON; back-slash problem

2009-12-15 Thread Ashley Sheridan
On Tue, 2009-12-15 at 06:52 -0500, Andrew Burgess wrote:

 This seems like a pretty basic question, but it has me stumped.
 
 Here's my scenario: I'm using Douglas Crockford's JSON2.js to parse an
 object in JavaScript, which I then pass to a PHP script to store in a
 file. I use JSON.stringify() on the object, which logs to the console
 as this:
 
 {employees:{data:{John:{fname:John,lname:Doe,city:Toronto,country:Canada
 
 Then I use the jQuery POST function to send it to a PHP script. Before
 doing anything with it in PHP, I log the received value to the
 console, and this is what I get:
 
 {\employees\:{\data\:{\John\:{\fname\:\John\,\lname\:\Doe\,\city\:\Toronto\,\country\:\Canada\
 
 The problem is, when I call the script to retrieve this data from a
 file, JSON.parse can't parse it because of the back-slashes. I'm
 pretty sure my problem is on the PHP side (since it's fine coming out
 of JS); what do I need to do to fix this? is a preg_replace enough?
 


Turn off magic quotes, as it looks like they are enabled on your server.
You can turn them off from the .htaccess file if you don't have access
to the php.ini

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




Re: [PHP] Parsing JSON; back-slash problem

2009-12-15 Thread Shawn McKenzie
Ashley Sheridan wrote:
 On Tue, 2009-12-15 at 06:52 -0500, Andrew Burgess wrote:
 
 This seems like a pretty basic question, but it has me stumped.

 Here's my scenario: I'm using Douglas Crockford's JSON2.js to parse an
 object in JavaScript, which I then pass to a PHP script to store in a
 file. I use JSON.stringify() on the object, which logs to the console
 as this:

 {employees:{data:{John:{fname:John,lname:Doe,city:Toronto,country:Canada

 Then I use the jQuery POST function to send it to a PHP script. Before
 doing anything with it in PHP, I log the received value to the
 console, and this is what I get:

 {\employees\:{\data\:{\John\:{\fname\:\John\,\lname\:\Doe\,\city\:\Toronto\,\country\:\Canada\

 The problem is, when I call the script to retrieve this data from a
 file, JSON.parse can't parse it because of the back-slashes. I'm
 pretty sure my problem is on the PHP side (since it's fine coming out
 of JS); what do I need to do to fix this? is a preg_replace enough?

 
 
 Turn off magic quotes, as it looks like they are enabled on your server.
 You can turn them off from the .htaccess file if you don't have access
 to the php.ini
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 

If you don't have access to do this, look at stripslashes()


-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] Parsing JSON; back-slash problem

2009-12-15 Thread Wouter van Vliet / Interpotential


 If you don't have access to do this, look at stripslashes()


And if you absolutely want to be on the safe side - check* if the
magic_quotes option is enabled - if so; do stripslashes. If not - then
obviously don't.

* http://www.php.net/manual/en/function.get-magic-quotes-gpc.php




 --
 Thanks!
 -Shawn
 http://www.spidean.com

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




-- 
http://www.interpotential.com
http://www.ilikealot.com

Phone: +4520371433


Re: [PHP] Parsing JSON; back-slash problem

2009-12-15 Thread Andrew Burgess
Thanks guys; I've got it working now!

On Tue, Dec 15, 2009 at 9:54 AM, Wouter van Vliet / Interpotential
pub...@interpotential.com wrote:

 If you don't have access to do this, look at stripslashes()

 And if you absolutely want to be on the safe side - check* if the
 magic_quotes option is enabled - if so; do stripslashes. If not - then
 obviously don't.
 * http://www.php.net/manual/en/function.get-magic-quotes-gpc.php


 --
 Thanks!
 -Shawn
 http://www.spidean.com

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




 --
 http://www.interpotential.com
 http://www.ilikealot.com

 Phone: +4520371433


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



[PHP] Re: newbie question - php parsing

2009-07-23 Thread Peter Ford
João Cândido de Souza Neto wrote:
 You made a mistake in your code:
 
 ?php the_title(); ?
 
 must be:
 
 ?php echo the_title(); ?
 

Not necessarily: what if you have

function the_title()
{
echo Title;
}

for example...


In response to Sebastiano:

There would be not much point in using something like PHP if it ignored the if
statements in the code!
What effectively happens in a PHP source file is that all the bits outside of
the ?php ? tags are treated like an echo statement (except that it handles
quotes and stuff nicely)

Your original code:

?php if (the_title('','',FALSE) != 'Home') { ?
h2 class=entry-header?php the_title(); ?/h2
?php } ?

can be read like:

?php
if (the_title('','',FALSE) != 'Home') {
echo 'h2 class=entry-header';
the_title();
echo '/h2';
}
?

You might even find a small (but probably really, really, really small)
performance improvement if you wrote it that way, especially if it was in some
kind of loop.
Note that I prefer to keep HTML separate from PHP as much as possible because it
helps me to read it and helps my editor check my syntax and HTML structure 
better...


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Re: newbie question - php parsing

2009-07-23 Thread Sebastiano Pomata
Thanks, it's now much more clear. I thought that html parts outside
php tags were just dumped to output, no matter of if-else statements
and other conditions. I was *definitely* wrong

2009/7/23 Peter Ford p...@justcroft.com:

 In response to Sebastiano:

 There would be not much point in using something like PHP if it ignored the 
 if
 statements in the code!
 What effectively happens in a PHP source file is that all the bits outside of
 the ?php ? tags are treated like an echo statement (except that it handles
 quotes and stuff nicely)

 Your original code:

 ?php if (the_title('','',FALSE) != 'Home') { ?
 h2 class=entry-header?php the_title(); ?/h2
 ?php } ?

 can be read like:

 ?php
 if (the_title('','',FALSE) != 'Home') {
    echo 'h2 class=entry-header';
    the_title();
    echo '/h2';
 }
 ?

 You might even find a small (but probably really, really, really small)
 performance improvement if you wrote it that way, especially if it was in some
 kind of loop.
 Note that I prefer to keep HTML separate from PHP as much as possible because 
 it
 helps me to read it and helps my editor check my syntax and HTML structure 
 better...


 --
 Peter Ford                              phone: 01580 89
 Developer                               fax:   01580 893399
 Justcroft International Ltd., Staplehurst, Kent

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



[PHP] newbie question - php parsing

2009-07-22 Thread Sebastiano Pomata
Hi all,

A little doubt caught me while I was writing this snippet of code for
a wordpress template:

?php if (the_title('','',FALSE) != 'Home') { ?
h2 class=entry-header?php the_title(); ?/h2
?php } ?

I always thought that php was called only between the ?php ? tags,
and I'm pretty sure that's right, while HTML code was simply wrote in
document as is, without further logic.
Now, I can't figure out how this snippet works: I mean, shouldn't HTML
code be simply put on document, as it is outside php invoke?
Effectively if the title of page is 'Home', the HTML part is totally
skipped.

Is the if construct that does all the magic inside?

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



[PHP] Re: newbie question - php parsing

2009-07-22 Thread Jo�o C�ndido de Souza Neto
You made a mistake in your code:

?php the_title(); ?

must be:

?php echo the_title(); ?

-- 
João Cândido de Souza Neto
SIENS SOLUÇÕES EM GESTÃO DE NEGÓCIOS
Fone: (0XX41) 3033-3636 - JS
www.siens.com.br

Sebastiano Pomata lafayett...@gmail.com escreveu na mensagem 
news:70fe20d60907221355m3fa49a75ua053d2f1b9aca...@mail.gmail.com...
 Hi all,

 A little doubt caught me while I was writing this snippet of code for
 a wordpress template:

 ?php if (the_title('','',FALSE) != 'Home') { ?
 h2 class=entry-header?php the_title(); ?/h2
 ?php } ?

 I always thought that php was called only between the ?php ? tags,
 and I'm pretty sure that's right, while HTML code was simply wrote in
 document as is, without further logic.
 Now, I can't figure out how this snippet works: I mean, shouldn't HTML
 code be simply put on document, as it is outside php invoke?
 Effectively if the title of page is 'Home', the HTML part is totally
 skipped.

 Is the if construct that does all the magic inside? 



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



Re: [PHP] Re: newbie question - php parsing

2009-07-22 Thread Shane Hill
2009/7/22 João Cândido de Souza Neto j...@consultorweb.cnt.br

 You made a mistake in your code:

 ?php the_title(); ?

 must be:

 ?php echo the_title(); ?


?= the_title(); ?

also works.

-Shane





 --
 João Cândido de Souza Neto
 SIENS SOLUÇÕES EM GESTÃO DE NEGÓCIOS
 Fone: (0XX41) 3033-3636 - JS
 www.siens.com.br

 Sebastiano Pomata lafayett...@gmail.com escreveu na mensagem
 news:70fe20d60907221355m3fa49a75ua053d2f1b9aca...@mail.gmail.com...
  Hi all,
 
  A little doubt caught me while I was writing this snippet of code for
  a wordpress template:
 
  ?php if (the_title('','',FALSE) != 'Home') { ?
  h2 class=entry-header?php the_title(); ?/h2
  ?php } ?
 
  I always thought that php was called only between the ?php ? tags,
  and I'm pretty sure that's right, while HTML code was simply wrote in
  document as is, without further logic.
  Now, I can't figure out how this snippet works: I mean, shouldn't HTML
  code be simply put on document, as it is outside php invoke?
  Effectively if the title of page is 'Home', the HTML part is totally
  skipped.
 
  Is the if construct that does all the magic inside?



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




Re: [PHP] Re: newbie question - php parsing

2009-07-22 Thread Lenin
Ted Turner http://www.brainyquote.com/quotes/authors/t/ted_turner.html  -
Sports is like a war without the killing.

2009/7/23 Shane Hill shanehil...@gmail.com

 2009/7/22 João Cândido de Souza Neto j...@consultorweb.cnt.br

  You made a mistake in your code:
 
  ?php the_title(); ?
 
  must be:
 
  ?php echo the_title(); ?


 ?= the_title(); ?


Short tag and not recommended as its deprecated now, would be void at PHP
6.0


Re: [PHP] Re: newbie question - php parsing

2009-07-22 Thread Martin Scotta
This is how I'd write this snippet

?php
if ( 'Home' !== ( $title = the_title('','',FALSE)))
{
echo 'h2 class=entry-header',
$title,
'/h2';
}
?

On Wed, Jul 22, 2009 at 6:31 PM, Lenin le...@phpxperts.net wrote:

 Ted Turner http://www.brainyquote.com/quotes/authors/t/ted_turner.html
  -
 Sports is like a war without the killing.

 2009/7/23 Shane Hill shanehil...@gmail.com

  2009/7/22 João Cândido de Souza Neto j...@consultorweb.cnt.br
 
   You made a mistake in your code:
  
   ?php the_title(); ?
  
   must be:
  
   ?php echo the_title(); ?
 
 
  ?= the_title(); ?


 Short tag and not recommended as its deprecated now, would be void at PHP
 6.0




-- 
Martin Scotta


[PHP] Re: newbie question - php parsing

2009-07-22 Thread Shawn McKenzie
João Cândido de Souza Neto wrote:
 You made a mistake in your code:
 
 ?php the_title(); ?
 
 must be:
 
 ?php echo the_title(); ?
 

I haven't used worpress in a long time, but the the_title() function
might echo the title unless you pass the FALSE parameter, in which case
it just returns it.

-- 
Thanks!
-Shawn
http://www.spidean.com

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



[PHP] Parsing of forms

2009-05-16 Thread Daniele Grillenzoni
I noticed that php's way to fill $_GET and $_POST is particularly 
inefficient when it comes to handling multiple inputs with the same name.


This basically mean that every select multiple in order to function 
properly needs to have a name ending in '[]'.


Wouldn't it be easier to also make it so that any element that has more 
than one value gets added to the GET/POST array as an array of strings 
instead of a string with the last value?


I can see the comfort of having the brackets system to create groups of 
inputs easily recognizable as such, while I can overlook the 
impossibility of having an input literally named 'foobar[]', having to 
add [] everytime there is a slight chance of two inputs with the same name.


This sounds flawed to me, as I could easily append '[]' to every input 
name and have a huge range of possibilities unlocked by that.


This can't be right. Or can it?

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



[PHP] Parsing of forms

2009-05-16 Thread Daniele Grillenzoni
I noticed that php's way to fill $_GET and $_POST is particularly 
inefficient when it comes to handling multiple inputs with the same name.


This basically mean that every select multiple in order to function 
properly needs to have a name ending in '[]'.


Wouldn't it be easier to also make it so that any element that has more 
than one value gets added to the GET/POST array as an array of strings 
instead of a string with the last value?


I can see the comfort of having the brackets system to create groups of 
inputs easily recognizable as such, while I can overlook the 
impossibility of having an input literally named 'foobar[]', having to 
add [] everytime there is a slight chance of two inputs with the same name.


This sounds flawed to me, as I could easily append '[]' to every input 
name and have a huge range of possibilities unlocked by that.


This can't be right. Or can it?

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



Re: [PHP] Parsing HTML href-Attribute

2009-01-18 Thread Benjamin Hawkes-Lewis

On 16/1/09 23:41, Shawn McKenzie wrote:

Again, I say that it won't work on URLs with spaces, like my web
page.html.  When I get a minute I'll fix it.  I thought spaces in URLs
weren't valid markup, but it seems to validate.


Some small points of information:

An HTML4 validator will only check that a HREF value is CDATA, as 
required by the DTD:


http://www.w3.org/TR/REC-html40/struct/links.html#adef-href

http://www.w3.org/TR/REC-html40/sgml/dtd.html#URI

http://www.w3.org/TR/REC-html40/types.html#type-cdata

Plenty of things can be CDATA without being a valid URI:

http://gbiv.com/protocols/uri/rfc/rfc3986.html

Space characters (U+0020) that are not percent encoded are not valid in 
a URI:


http://gbiv.com/protocols/uri/rfc/rfc3986.html#collected-abnf

That's not to say that browsers haven't developed error handling for 
space characters (and other illegal characters) in HREF values.


The HTML5 draft proposes an algorithm for parsing and resolving HREF 
values that includes such error handling:


http://www.whatwg.org/specs/web-apps/current-work/#parsing-urls

http://www.whatwg.org/specs/web-apps/current-work/#resolving-urls

--
Benjamin Hawkes-Lewis

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



Re: [PHP] Parsing HTML href-Attribute

2009-01-18 Thread Micah Gersten
Depending on the goal, using the base tag in the head section might help:
http://www.w3.org/TR/REC-html40/struct/links.html#h-12.4

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Edmund Hertle wrote:
 Hey,
 I want to parse a href-attribute in a given String to check if there is a
 relative link and then adding an absolute path.
 Example:
 $string  = 'a class=sample [...additional attributes...]
 href=/foo/bar.php ';

 I tried using regular expressions but my knowledge of RegEx is very limited.
 Things to consider:
 - $string could be quite long but my concern are only those href attributes
 (so working with explode() would be not very handy)
 - Should also work if href= is not using quotes or using single quotes
 - link could already be an absolute path, so just searching for href= and
 then inserting absolute path could mess up the link

 Any ideas? Or can someone create a RegEx to use?

 Thanks

   

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



RE: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Boyd, Todd M.
 -Original Message-
 From: farn...@googlemail.com [mailto:farn...@googlemail.com] On Behalf
 Of Edmund Hertle
 Sent: Thursday, January 15, 2009 4:13 PM
 To: PHP - General
 Subject: [PHP] Parsing HTML href-Attribute
 
 Hey,
 I want to parse a href-attribute in a given String to check if there
 is a
 relative link and then adding an absolute path.
 Example:
 $string  = 'a class=sample [...additional attributes...]
 href=/foo/bar.php ';
 
 I tried using regular expressions but my knowledge of RegEx is very
 limited.
 Things to consider:
 - $string could be quite long but my concern are only those href
 attributes
 (so working with explode() would be not very handy)
 - Should also work if href= is not using quotes or using single quotes
 - link could already be an absolute path, so just searching for href=
 and
 then inserting absolute path could mess up the link
 
 Any ideas? Or can someone create a RegEx to use?

Just spitballing here, but this is probably how I would start:

RegEx pattern: /a.*? href=(.+?)/ig

Then, using the capture group, determine if the href attribute uses quotes 
(single or double, doesn't matter). If it does, you don't need to worry about 
splitting the capture group at the first white space. If it doesn't, then you 
must assume the first whitespace is the end of the URL and the beginning of 
additional attributes, and just grab the URL up to (but not including) the 
first whitespace.

So...

?php

# here is where $anchorText (text for the a tag) would be assigned
# here is where $curDir (text for the current directory) would be assigned

# find the href attribute
$matches = Array();
preg_match('#a.*? href=(.+?)#ig', $anchorText, $matches);

# determine if it has surrounding quotes
if($matches[1][0] == '\'' || $matches[1][0] == '')
{
# pull everything but the first and last character
$anchorText = substr($anchorText, 1, strlen($anchorText) - 3);
}
else
{
# pull up to the first space (if there is one)
$spacePos = strpos($anchorText, ' ');   
if($spacePos !== false) 
$anchorText = substr($anchorText, 0, strpos($anchorText, ' '))
}

# now, check to see if it is relative or absolute
# (regex pattern searches for protocol spec (i.e., http://), which will be
# treated as an absolute path for the purpose of this algorithm)
if($anchorText[0] != '/'  preg_match('#^\w+://#', $anchorText) == 0)
{
# add current directory to the beginning of the relative path
# (nothing is done to absolute paths or URLs with protocol spec)
$anchorText = $curDir . '/' . $anchorText;
}

echo $anchorText;

?

...UNTESTED.

HTH,


// Todd


Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Shawn McKenzie
Boyd, Todd M. wrote:
 -Original Message-
 From: farn...@googlemail.com [mailto:farn...@googlemail.com] On Behalf
 Of Edmund Hertle
 Sent: Thursday, January 15, 2009 4:13 PM
 To: PHP - General
 Subject: [PHP] Parsing HTML href-Attribute

 Hey,
 I want to parse a href-attribute in a given String to check if there
 is a
 relative link and then adding an absolute path.
 Example:
 $string  = 'a class=sample [...additional attributes...]
 href=/foo/bar.php ';

 I tried using regular expressions but my knowledge of RegEx is very
 limited.
 Things to consider:
 - $string could be quite long but my concern are only those href
 attributes
 (so working with explode() would be not very handy)
 - Should also work if href= is not using quotes or using single quotes
 - link could already be an absolute path, so just searching for href=
 and
 then inserting absolute path could mess up the link

 Any ideas? Or can someone create a RegEx to use?
 
 Just spitballing here, but this is probably how I would start:
 
 RegEx pattern: /a.*? href=(.+?)/ig
 
 Then, using the capture group, determine if the href attribute uses quotes 
 (single or double, doesn't matter). If it does, you don't need to worry about 
 splitting the capture group at the first white space. If it doesn't, then you 
 must assume the first whitespace is the end of the URL and the beginning of 
 additional attributes, and just grab the URL up to (but not including) the 
 first whitespace.
 
 So...
 
 ?php
 
 # here is where $anchorText (text for the a tag) would be assigned
 # here is where $curDir (text for the current directory) would be assigned
 
 # find the href attribute
 $matches = Array();
 preg_match('#a.*? href=(.+?)#ig', $anchorText, $matches);
 
 # determine if it has surrounding quotes
 if($matches[1][0] == '\'' || $matches[1][0] == '')
 {
   # pull everything but the first and last character
   $anchorText = substr($anchorText, 1, strlen($anchorText) - 3);
 }
 else
 {
   # pull up to the first space (if there is one)
   $spacePos = strpos($anchorText, ' ');   
   if($spacePos !== false) 
   $anchorText = substr($anchorText, 0, strpos($anchorText, ' '))
 }
 
 # now, check to see if it is relative or absolute
 # (regex pattern searches for protocol spec (i.e., http://), which will be
 # treated as an absolute path for the purpose of this algorithm)
 if($anchorText[0] != '/'  preg_match('#^\w+://#', $anchorText) == 0)
 {
   # add current directory to the beginning of the relative path
   # (nothing is done to absolute paths or URLs with protocol spec)
   $anchorText = $curDir . '/' . $anchorText;
 }
 
 echo $anchorText;
 
 ?
 
 ...UNTESTED.
 
 HTH,
 
 
 // Todd

Wow, that's alot!  This should work with or without quotes and assumes
no spaces in the URL:

$prefix = http://example.com/;;
$html = preg_replace(|(href=['\]?)(?!$prefix)([^'\\s]+)(\s)?|,
$1$prefix$2$3, $html);


-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Eric Butera
On Thu, Jan 15, 2009 at 5:13 PM, Edmund Hertle
edmund.her...@student.kit.edu wrote:
 Hey,
 I want to parse a href-attribute in a given String to check if there is a
 relative link and then adding an absolute path.
 Example:
 $string  = 'a class=sample [...additional attributes...]
 href=/foo/bar.php ';

 I tried using regular expressions but my knowledge of RegEx is very limited.
 Things to consider:
 - $string could be quite long but my concern are only those href attributes
 (so working with explode() would be not very handy)
 - Should also work if href= is not using quotes or using single quotes
 - link could already be an absolute path, so just searching for href= and
 then inserting absolute path could mess up the link

 Any ideas? Or can someone create a RegEx to use?

 Thanks


You could also use DOM for this.

http://us2.php.net/manual/en/domdocument.getelementsbytagname.php

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



Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread mike
On Fri, Jan 16, 2009 at 10:54 AM, Eric Butera eric.but...@gmail.com wrote:

 You could also use DOM for this.

 http://us2.php.net/manual/en/domdocument.getelementsbytagname.php

only if it's parseable xml :)

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



Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread mike
On Fri, Jan 16, 2009 at 10:58 AM, mike mike...@gmail.com wrote:

 only if it's parseable xml :)


Or not! Ignore me. Supposedly this can handle HTML too. I'll have to
try it next time. Normally I wind up having to use tidy to scrub a
document and try to get it into xhtml and then use simplexml. I wonder
how well this would work with [crappy] HTML input.

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



Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Eric Butera
On Fri, Jan 16, 2009 at 1:59 PM, mike mike...@gmail.com wrote:
 On Fri, Jan 16, 2009 at 10:58 AM, mike mike...@gmail.com wrote:

 only if it's parseable xml :)


 Or not! Ignore me. Supposedly this can handle HTML too. I'll have to
 try it next time. Normally I wind up having to use tidy to scrub a
 document and try to get it into xhtml and then use simplexml. I wonder
 how well this would work with [crappy] HTML input.


Great if you use @.  ;)  I'd try to make sure all of my input was
stored as proper x/html in the db before I really tried parsing it, so
I'm not sure of his setup, but I use getElementsByTagName all the time
and love it.

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



Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Shawn McKenzie
Shawn McKenzie wrote:
 Boyd, Todd M. wrote:
 -Original Message-
 From: farn...@googlemail.com [mailto:farn...@googlemail.com] On Behalf
 Of Edmund Hertle
 Sent: Thursday, January 15, 2009 4:13 PM
 To: PHP - General
 Subject: [PHP] Parsing HTML href-Attribute

 Hey,
 I want to parse a href-attribute in a given String to check if there
 is a
 relative link and then adding an absolute path.
 Example:
 $string  = 'a class=sample [...additional attributes...]
 href=/foo/bar.php ';

 I tried using regular expressions but my knowledge of RegEx is very
 limited.
 Things to consider:
 - $string could be quite long but my concern are only those href
 attributes
 (so working with explode() would be not very handy)
 - Should also work if href= is not using quotes or using single quotes
 - link could already be an absolute path, so just searching for href=
 and
 then inserting absolute path could mess up the link

 Any ideas? Or can someone create a RegEx to use?
 Just spitballing here, but this is probably how I would start:

 RegEx pattern: /a.*? href=(.+?)/ig

 Then, using the capture group, determine if the href attribute uses quotes 
 (single or double, doesn't matter). If it does, you don't need to worry 
 about splitting the capture group at the first white space. If it doesn't, 
 then you must assume the first whitespace is the end of the URL and the 
 beginning of additional attributes, and just grab the URL up to (but not 
 including) the first whitespace.

 So...

 ?php

 # here is where $anchorText (text for the a tag) would be assigned
 # here is where $curDir (text for the current directory) would be assigned

 # find the href attribute
 $matches = Array();
 preg_match('#a.*? href=(.+?)#ig', $anchorText, $matches);

 # determine if it has surrounding quotes
 if($matches[1][0] == '\'' || $matches[1][0] == '')
 {
  # pull everything but the first and last character
  $anchorText = substr($anchorText, 1, strlen($anchorText) - 3);
 }
 else
 {
  # pull up to the first space (if there is one)
  $spacePos = strpos($anchorText, ' ');   
  if($spacePos !== false) 
  $anchorText = substr($anchorText, 0, strpos($anchorText, ' '))
 }

 # now, check to see if it is relative or absolute
 # (regex pattern searches for protocol spec (i.e., http://), which will be
 # treated as an absolute path for the purpose of this algorithm)
 if($anchorText[0] != '/'  preg_match('#^\w+://#', $anchorText) == 0)
 {
  # add current directory to the beginning of the relative path
  # (nothing is done to absolute paths or URLs with protocol spec)
  $anchorText = $curDir . '/' . $anchorText;
 }

 echo $anchorText;

 ?

 ...UNTESTED.

 HTH,


 // Todd
 
 Wow, that's alot!  This should work with or without quotes and assumes
 no spaces in the URL:
 
 $prefix = http://example.com/;;
 $html = preg_replace(|(href=['\]?)(?!$prefix)([^'\\s]+)(\s)?|,
 $1$prefix$2$3, $html);
 
 
Might need to keep a preceding slash out of there:

$html = preg_replace(|(href=['\]?)(?!$prefix)[/]?([^'\\s]+)(\s)?|,
$1$prefix$2$3, $html);

-- 
Thanks!
-Shawn
http://www.spidean.com

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



RE: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Boyd, Todd M.
 -Original Message-
 From: Shawn McKenzie [mailto:nos...@mckenzies.net]
 Sent: Friday, January 16, 2009 1:08 PM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Parsing HTML href-Attribute
 
 Shawn McKenzie wrote:
  Boyd, Todd M. wrote:
  -Original Message-
  From: farn...@googlemail.com [mailto:farn...@googlemail.com] On
 Behalf
  Of Edmund Hertle
  Sent: Thursday, January 15, 2009 4:13 PM
  To: PHP - General
  Subject: [PHP] Parsing HTML href-Attribute
 
  Hey,
  I want to parse a href-attribute in a given String to check if
 there
  is a
  relative link and then adding an absolute path.
  Example:
  $string  = 'a class=sample [...additional attributes...]
  href=/foo/bar.php ';
 
  I tried using regular expressions but my knowledge of RegEx is very
  limited.
  Things to consider:
  - $string could be quite long but my concern are only those href
  attributes
  (so working with explode() would be not very handy)
  - Should also work if href= is not using quotes or using single
 quotes
  - link could already be an absolute path, so just searching for
 href=
  and
  then inserting absolute path could mess up the link
 
  Any ideas? Or can someone create a RegEx to use?
  Just spitballing here, but this is probably how I would start:
 
  RegEx pattern: /a.*? href=(.+?)/ig
 
  Then, using the capture group, determine if the href attribute uses
 quotes (single or double, doesn't matter). If it does, you don't need
 to worry about splitting the capture group at the first white space. If
 it doesn't, then you must assume the first whitespace is the end of the
 URL and the beginning of additional attributes, and just grab the URL
 up to (but not including) the first whitespace.
 
  So...
 
  ?php
 
  # here is where $anchorText (text for the a tag) would be assigned
  # here is where $curDir (text for the current directory) would be
 assigned
 
  # find the href attribute
  $matches = Array();
  preg_match('#a.*? href=(.+?)#ig', $anchorText, $matches);
 
  # determine if it has surrounding quotes
  if($matches[1][0] == '\'' || $matches[1][0] == '')
  {
 # pull everything but the first and last character
 $anchorText = substr($anchorText, 1, strlen($anchorText) - 3);
  }
  else
  {
 # pull up to the first space (if there is one)
 $spacePos = strpos($anchorText, ' ');
 if($spacePos !== false)
 $anchorText = substr($anchorText, 0, strpos($anchorText, '
 '))
  }
 
  # now, check to see if it is relative or absolute
  # (regex pattern searches for protocol spec (i.e., http://), which
 will be
  # treated as an absolute path for the purpose of this algorithm)
  if($anchorText[0] != '/'  preg_match('#^\w+://#', $anchorText) ==
 0)
  {
 # add current directory to the beginning of the relative path
 # (nothing is done to absolute paths or URLs with protocol spec)
 $anchorText = $curDir . '/' . $anchorText;
  }
 
  echo $anchorText;
 
  ?
 
  ...UNTESTED.
 
  HTH,
 
 
  // Todd
 
  Wow, that's alot!  This should work with or without quotes and
 assumes
  no spaces in the URL:
 
  $prefix = http://example.com/;;
  $html = preg_replace(|(href=['\]?)(?!$prefix)([^'\\s]+)(\s)?|,
  $1$prefix$2$3, $html);
 
 
 Might need to keep a preceding slash out of there:
 
 $html = preg_replace(|(href=['\]?)(?!$prefix)[/]?([^'\\s]+)(\s)?|,
 $1$prefix$2$3, $html);

I believe the OP wanted to leave already-absolute paths alone (i.e., only 
convert relative paths). The regex does not take into account fully-qualified 
URLs (i.e., http://www.google.com/search?q=php) and it does not determine if a 
given path is relative or absolute. He was wanting to take the href attribute 
of an anchor tag and, **IF** it was a relative path, turn it into an absolute 
path (meaning to append the relative path to the absolute path of the current 
script).

That was my understanding. Perhaps you saw it differently, but I don't believe 
your pattern is enough to accomplish what the OP was asking for--hence a lot 
of code was in my reply. ;)

Believe me, I'm the first guy to hop on the do it with a regex! bandwagon... 
but there are just some circumstances where regex can't do what you need to do 
(such as more-than-superficial contextual logic).

HTH,


// Todd


Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Shawn McKenzie
Boyd, Todd M. wrote:
 -Original Message- From: Shawn McKenzie 
 [mailto:nos...@mckenzies.net] Sent: Friday, January 16, 2009 1:08 
 PM To: php-general@lists.php.net Subject: Re: [PHP] Parsing HTML 
 href-Attribute
 
 Shawn McKenzie wrote:
 Boyd, Todd M. wrote:
 -Original Message- From: farn...@googlemail.com 
 [mailto:farn...@googlemail.com] On
 Behalf
 Of Edmund Hertle Sent: Thursday, January 15, 2009 4:13 PM To:
  PHP - General Subject: [PHP] Parsing HTML href-Attribute
 
 Hey, I want to parse a href-attribute in a given String to 
 check if
 there
 is a relative link and then adding an absolute path. Example:
  $string  = 'a class=sample [...additional attributes...]
  href=/foo/bar.php ';
 
 I tried using regular expressions but my knowledge of RegEx 
 is very limited. Things to consider: - $string could be quite
  long but my concern are only those href attributes (so 
 working with explode() would be not very handy) - Should also
  work if href= is not using quotes or using single
 quotes
 - link could already be an absolute path, so just searching 
 for
 href=
 and then inserting absolute path could mess up the link
 
 Any ideas? Or can someone create a RegEx to use?
 Just spitballing here, but this is probably how I would start:
 
 RegEx pattern: /a.*? href=(.+?)/ig
 
 Then, using the capture group, determine if the href attribute 
 uses
 quotes (single or double, doesn't matter). If it does, you don't 
 need to worry about splitting the capture group at the first white 
 space. If it doesn't, then you must assume the first whitespace is 
 the end of the URL and the beginning of additional attributes, and 
 just grab the URL up to (but not including) the first whitespace.
 So...
 
 ?php
 
 # here is where $anchorText (text for the a tag) would be 
 assigned # here is where $curDir (text for the current 
 directory) would be
 assigned
 # find the href attribute $matches = Array(); 
 preg_match('#a.*? href=(.+?)#ig', $anchorText, $matches);
 
 # determine if it has surrounding quotes if($matches[1][0] == 
 '\'' || $matches[1][0] == '') { # pull everything but the 
 first and last character $anchorText = substr($anchorText, 1, 
 strlen($anchorText) - 3); } else { # pull up to the first space
  (if there is one) $spacePos = strpos($anchorText, ' '); 
 if($spacePos !== false) $anchorText = substr($anchorText, 0, 
 strpos($anchorText, '
 '))
 }
 
 # now, check to see if it is relative or absolute # (regex 
 pattern searches for protocol spec (i.e., http://), which
 will be
 # treated as an absolute path for the purpose of this 
 algorithm) if($anchorText[0] != '/'  preg_match('#^\w+://#', 
 $anchorText) ==
 0)
 { # add current directory to the beginning of the relative path
  # (nothing is done to absolute paths or URLs with protocol 
 spec) $anchorText = $curDir . '/' . $anchorText; }
 
 echo $anchorText;
 
 ?
 
 ...UNTESTED.
 
 HTH,
 
 
 // Todd
 Wow, that's alot!  This should work with or without quotes and
 assumes
 no spaces in the URL:
 
 $prefix = http://example.com/;; $html = 
 preg_replace(|(href=['\]?)(?!$prefix)([^'\\s]+)(\s)?|, 
 $1$prefix$2$3, $html);
 
 
 Might need to keep a preceding slash out of there:
 
 $html = 
 preg_replace(|(href=['\]?)(?!$prefix)[/]?([^'\\s]+)(\s)?|, 
 $1$prefix$2$3, $html);
 
 I believe the OP wanted to leave already-absolute paths alone (i.e., 
 only convert relative paths). The regex does not take into account 
 fully-qualified URLs (i.e., http://www.google.com/search?q=php) and 
 it does not determine if a given path is relative or absolute. He was
  wanting to take the href attribute of an anchor tag and, **IF** it 
 was a relative path, turn it into an absolute path (meaning to append
  the relative path to the absolute path of the current script).

That's exactly what this regex does :-)  The (?!$prefix) negative
lookahead assertion fails the match if it's already an absolute URL.

 That was my understanding. Perhaps you saw it differently, but I 
 don't believe your pattern is enough to accomplish what the OP was 
 asking for--hence a lot of code was in my reply. ;)
 
 Believe me, I'm the first guy to hop on the do it with a regex! 
 bandwagon... but there are just some circumstances where regex can't 
 do what you need to do (such as more-than-superficial contextual 
 logic).
 
 HTH,
 
 
 // Todd


-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Shawn McKenzie
 I believe the OP wanted to leave already-absolute paths alone
 (i.e., only convert relative paths). The regex does not take into
 account fully-qualified URLs (i.e.,
 http://www.google.com/search?q=php) and it does not determine if a
 given path is relative or absolute. He was wanting to take the href
 attribute of an anchor tag and, **IF** it was a relative path, turn
 it into an absolute path (meaning to append the relative path to
 the absolute path of the current script).
 
 That's exactly what this regex does :-)  The (?!$prefix) negative 
 lookahead assertion fails the match if it's already an absolute URL.
 
 That was my understanding. Perhaps you saw it differently, but I 
 don't believe your pattern is enough to accomplish what the OP was
  asking for--hence a lot of code was in my reply. ;)
 
 Believe me, I'm the first guy to hop on the do it with a regex! 
 bandwagon... but there are just some circumstances where regex
 can't do what you need to do (such as more-than-superficial
 contextual logic).
 
 HTH,
 
 
 // Todd
 
Ahh, but you uncovered a problem for me if the href contains an
absolute URL that doesn't contain the prefix.  Here's the fix:

$html =
preg_replace(|(href=['\]?)(?!http(?:s)?://)[/]?([^'\\s]+)(\s)?|,
$1http://www.example.com/2$3;, $html);

-- 
Thanks!
-Shawn
http://www.spidean.com

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



RE: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Boyd, Todd M.
 -Original Message-
 From: Shawn McKenzie [mailto:nos...@mckenzies.net]
 Sent: Friday, January 16, 2009 2:37 PM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Parsing HTML href-Attribute
 
  Hey, I want to parse a href-attribute in a given String to
  check if
  there
  is a relative link and then adding an absolute path. Example:
   $string  = 'a class=sample [...additional attributes...]
   href=/foo/bar.php ';
 
  I tried using regular expressions but my knowledge of RegEx
  is very limited. Things to consider: - $string could be quite
   long but my concern are only those href attributes (so
  working with explode() would be not very handy) - Should also
   work if href= is not using quotes or using single
  quotes
  - link could already be an absolute path, so just searching
  for
  href=
  and then inserting absolute path could mess up the link
 
  Any ideas? Or can someone create a RegEx to use?
  Just spitballing here, but this is probably how I would start:
 
  RegEx pattern: /a.*? href=(.+?)/ig
 
  Then, using the capture group, determine if the href attribute
  uses
  quotes (single or double, doesn't matter). If it does, you don't
  need to worry about splitting the capture group at the first white
  space. If it doesn't, then you must assume the first whitespace is
  the end of the URL and the beginning of additional attributes, and
  just grab the URL up to (but not including) the first whitespace.
  So...
 
  ?php
 
  # here is where $anchorText (text for the a tag) would be
  assigned # here is where $curDir (text for the current
  directory) would be
  assigned
  # find the href attribute $matches = Array();
  preg_match('#a.*? href=(.+?)#ig', $anchorText, $matches);
 
  # determine if it has surrounding quotes if($matches[1][0] ==
  '\'' || $matches[1][0] == '') { # pull everything but the
  first and last character $anchorText = substr($anchorText, 1,
  strlen($anchorText) - 3); } else { # pull up to the first space
   (if there is one) $spacePos = strpos($anchorText, ' ');
  if($spacePos !== false) $anchorText = substr($anchorText, 0,
  strpos($anchorText, '
  '))
  }
 
  # now, check to see if it is relative or absolute # (regex
  pattern searches for protocol spec (i.e., http://), which
  will be
  # treated as an absolute path for the purpose of this
  algorithm) if($anchorText[0] != '/'  preg_match('#^\w+://#',
  $anchorText) ==
  0)
  { # add current directory to the beginning of the relative path
   # (nothing is done to absolute paths or URLs with protocol
  spec) $anchorText = $curDir . '/' . $anchorText; }
 
  echo $anchorText;
 
  ?
 
  Wow, that's alot!  This should work with or without quotes and
  assumes
  no spaces in the URL:
 
  $prefix = http://example.com/;; $html =
  preg_replace(|(href=['\]?)(?!$prefix)([^'\\s]+)(\s)?|,
  $1$prefix$2$3, $html);
 
 
  Might need to keep a preceding slash out of there:
 
  $html =
  preg_replace(|(href=['\]?)(?!$prefix)[/]?([^'\\s]+)(\s)?|,
  $1$prefix$2$3, $html);
 
  I believe the OP wanted to leave already-absolute paths alone (i.e.,
  only convert relative paths). The regex does not take into account
  fully-qualified URLs (i.e., http://www.google.com/search?q=php) and
  it does not determine if a given path is relative or absolute. He was
   wanting to take the href attribute of an anchor tag and, **IF** it
  was a relative path, turn it into an absolute path (meaning to append
   the relative path to the absolute path of the current script).
 
 That's exactly what this regex does :-)  The (?!$prefix) negative
 lookahead assertion fails the match if it's already an absolute URL.

I see that now. I didn't notice the negative look-ahead the first go 'round. 
However, I still have qualms with it. :) You are only checking for http://, and 
only for the local server. What I meant by absolute path was, for example, 
/index.php (the index in the root directory of the server) as opposed to 
somefolder/index.php (the index in a subfolder of the current directory named 
'somefolder').

* http://www.google.com/search?q=php ... absolute path (yes, it's a URL, but 
treat it as absolute)
* https://www.example.com/index.php ... absolute path (yes, it's a URL, but to 
the local server)
* /index.php ... absolute path (no protocol given, true absolute path)
* index.php ... relative path (relative to current directory on current server)
* somefolder/index.php ... relative path (same reason)

That is indeed a nifty use of look-ahead, though. That will work for any anchor 
tag that doesn't reference the server (or any other server) with a protocol 
spec preceding it. However, if you want to run it through an entire list of 
anchor tags with any spec (http://, https://, udp://, ftp://, aim://, rss://, 
etc.)--or lack of spec--and only mess with those that don't have a spec and 
don't use absolute paths, it needs to get a bit more complex. You've convinced 
me, however, that it can be done entirely with one regex pattern.

Ooh--one more

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Edmund Hertle

 * http://www.google.com/search?q=php ... absolute path (yes, it's a URL,
 but treat it as absolute)
 * https://www.example.com/index.php ... absolute path (yes, it's a URL,
 but to the local server)
 * /index.php ... absolute path (no protocol given, true absolute path)
 * index.php ... relative path (relative to current directory on current
 server)
 * somefolder/index.php ... relative path (same reason)

 That is indeed a nifty use of look-ahead, though. That will work for any
 anchor tag that doesn't reference the server (or any other server) with a
 protocol spec preceding it. However, if you want to run it through an entire
 list of anchor tags with any spec (http://, https://, udp://, ftp://,
 aim://, rss://, etc.)--or lack of spec--and only mess with those that don't
 have a spec and don't use absolute paths, it needs to get a bit more
 complex. You've convinced me, however, that it can be done entirely with one
 regex pattern.

 // Todd


Hey!
Wow, I think that was exactly what I was looking for... thank all of you...
although I've not tested it, will do that tomorrow, but sounds very nice

But Todd just confused me quite a bit with the statement: Is /index.php a
case where the RegEx will fail?

To add some background: It is about dynamiclly creating pdf files out of
html source code and then the links should also work in the pdf file. So
other protocolls then http:// shouldn't be a problem

-eddy


Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Kevin Waterson
This one time, at band camp, mike mike...@gmail.com wrote:

 On Fri, Jan 16, 2009 at 10:58 AM, mike mike...@gmail.com wrote:
 
  only if it's parseable xml :)
 
 
 Or not! Ignore me. Supposedly this can handle HTML too. I'll have to
 try it next time. Normally I wind up having to use tidy to scrub a
 document and try to get it into xhtml and then use simplexml. I wonder
 how well this would work with [crappy] HTML input.

$dom-loadHTML($html)

Kevin

http://phpro.org

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



Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Kevin Waterson
This one time, at band camp, Eric Butera eric.but...@gmail.com wrote:

 
 You could also use DOM for this.
 
 http://us2.php.net/manual/en/domdocument.getelementsbytagname.php

http://www.phpro.org/examples/Get-Links-With-DOM.html


Kevin

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



Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Shawn McKenzie
Edmund Hertle wrote:
 * http://www.google.com/search?q=php ... absolute path (yes, it's a URL,
 but treat it as absolute)
 * https://www.example.com/index.php ... absolute path (yes, it's a URL,
 but to the local server)
 * /index.php ... absolute path (no protocol given, true absolute path)
 * index.php ... relative path (relative to current directory on current
 server)
 * somefolder/index.php ... relative path (same reason)

 That is indeed a nifty use of look-ahead, though. That will work for any
 anchor tag that doesn't reference the server (or any other server) with a
 protocol spec preceding it. However, if you want to run it through an entire
 list of anchor tags with any spec (http://, https://, udp://, ftp://,
 aim://, rss://, etc.)--or lack of spec--and only mess with those that don't
 have a spec and don't use absolute paths, it needs to get a bit more
 complex. You've convinced me, however, that it can be done entirely with one
 regex pattern.

 // Todd
 
 
 Hey!
 Wow, I think that was exactly what I was looking for... thank all of you...
 although I've not tested it, will do that tomorrow, but sounds very nice
 
 But Todd just confused me quite a bit with the statement: Is /index.php a
 case where the RegEx will fail?
 
 To add some background: It is about dynamiclly creating pdf files out of
 html source code and then the links should also work in the pdf file. So
 other protocolls then http:// shouldn't be a problem
 
 -eddy
 
That regex should work on all hrefs. index.php and /index.php will be
replaced with http://www.example.com/index.php and somedir/index.php and
/somedir/index.php will be replaced with
http://www.example.com/somedir/index.php.  Any URL starting with http://
or https:// will be ignored.

Again, I say that it won't work on URLs with spaces, like my web
page.html.  When I get a minute I'll fix it.  I thought spaces in URLs
weren't valid markup, but it seems to validate.

-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Eric Butera
On Fri, Jan 16, 2009 at 6:18 PM, Kevin Waterson ke...@phpro.org wrote:
 This one time, at band camp, Eric Butera eric.but...@gmail.com wrote:


 You could also use DOM for this.

 http://us2.php.net/manual/en/domdocument.getelementsbytagname.php

 http://www.phpro.org/examples/Get-Links-With-DOM.html


 Kevin

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



Nice ;)

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



[PHP] Parsing HTML href-Attribute

2009-01-15 Thread Edmund Hertle
Hey,
I want to parse a href-attribute in a given String to check if there is a
relative link and then adding an absolute path.
Example:
$string  = 'a class=sample [...additional attributes...]
href=/foo/bar.php ';

I tried using regular expressions but my knowledge of RegEx is very limited.
Things to consider:
- $string could be quite long but my concern are only those href attributes
(so working with explode() would be not very handy)
- Should also work if href= is not using quotes or using single quotes
- link could already be an absolute path, so just searching for href= and
then inserting absolute path could mess up the link

Any ideas? Or can someone create a RegEx to use?

Thanks


Re: [PHP] Parsing HTML href-Attribute

2009-01-15 Thread Murray
Hi Edmund,

You want a regex that looks something like this:

$result = preg_replace('%(href=)(|\')(?!c:/)(.+?)(|\')%',
'\1\2c:/my_absolute_path\3\4', $subject);

This example assumes that your absolute path begins with c:/. You would
change this to whatever suits. You would also change c:/my_absolute_path
to be whatever appropriate value indicates the absolute path element that
you want to prepend.

Note: this will NOT accound for hrefs that are not encapsulated in either '
or . The problem being that while you can probably predictably how the
substring starts, it would be more difficult to determine how it ends,
unless you can provide a white list of file extensions for the regex (ie, if
you know you only ever link to, for example, files with .php and or .html
extensions). In that case, you probably could alter the regex to test for
these instead of a ' or .

M is for Murray


On Fri, Jan 16, 2009 at 8:13 AM, Edmund Hertle 
edmund.her...@student.kit.edu wrote:

 Hey,
 I want to parse a href-attribute in a given String to check if there is a
 relative link and then adding an absolute path.
 Example:
 $string  = 'a class=sample [...additional attributes...]
 href=/foo/bar.php ';

 I tried using regular expressions but my knowledge of RegEx is very
 limited.
 Things to consider:
 - $string could be quite long but my concern are only those href attributes
 (so working with explode() would be not very handy)
 - Should also work if href= is not using quotes or using single quotes
 - link could already be an absolute path, so just searching for href= and
 then inserting absolute path could mess up the link

 Any ideas? Or can someone create a RegEx to use?

 Thanks



Re: [PHP] Parsing Strings

2008-12-07 Thread German Geek
Why not preg_split ( http://nz.php.net/manual/en/function.preg-split.php ):

$str = 'SCOTTSDALE, AZ 85254';
$ar = preg_split('/,? ?/', $str); //optional comma, followed by optional
space
// $ar = array('SCOTTSDALE', 'AZ', '85254');

On Sat, Dec 6, 2008 at 1:18 PM, Jason Todd Slack-Moehrle 
[EMAIL PROTECTED] wrote:


 How might I also parse and address like: SCOTTSDALE, AZ 85254

 It has a comma and a space

 -Jason


 On Dec 5, 2008, at 4:02 PM, Jason Todd Slack-Moehrle wrote:

  OK, making good learning progress today.

 I have a string that is: Jason Slack

 and I want it broken at the space so i get Jason and then Slack

 I am looking at parse_str, but I dont get how to do it with a space. The
 example is using []=.

 Then I want to assign like:

 $fname = Jason;
 $lname = Slack;

 Any ideas?

 -Jason

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





-- 
Tim-Hinnerk Heuer

http://www.ihostnz.com -- Web Design, Hosting and free Linux Support


Re: [PHP] Parsing Strings

2008-12-06 Thread tedd

At 4:18 PM -0800 12/5/08, Jason Todd Slack-Moehrle wrote:

How might I also parse and address like: SCOTTSDALE, AZ 85254

It has a comma and a space

-Jason

On Dec 5, 2008, at 4:02 PM, Jason Todd Slack-Moehrle wrote:


OK, making good learning progress today.

I have a string that is: Jason Slack

and I want it broken at the space so i get Jason and then Slack

I am looking at parse_str, but I dont get how to do it with a 
space. The example is using []=.


Then I want to assign like:

$fname = Jason;
$lname = Slack;

Any ideas?

-Jason


-Jason:

This is pretty basic stuff -- read the manuals about strings:

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

If you have shown that you've spent time reading and then have a 
problem, please post your question. But don't expect us to do your 
homework for you.


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] Parsing Strings

2008-12-06 Thread VamVan
u can use split() or explode ().

Thanks

On Sat, Dec 6, 2008 at 9:27 AM, tedd [EMAIL PROTECTED] wrote:

 At 4:18 PM -0800 12/5/08, Jason Todd Slack-Moehrle wrote:

 How might I also parse and address like: SCOTTSDALE, AZ 85254

 It has a comma and a space

 -Jason

 On Dec 5, 2008, at 4:02 PM, Jason Todd Slack-Moehrle wrote:

  OK, making good learning progress today.

 I have a string that is: Jason Slack

 and I want it broken at the space so i get Jason and then Slack

 I am looking at parse_str, but I dont get how to do it with a space. The
 example is using []=.

 Then I want to assign like:

 $fname = Jason;
 $lname = Slack;

 Any ideas?

 -Jason


 -Jason:

 This is pretty basic stuff -- read the manuals about strings:

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

 If you have shown that you've spent time reading and then have a problem,
 please post your question. But don't expect us to do your homework for you.

 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] Parsing Strings

2008-12-06 Thread Nathan Rixham

tedd wrote:

At 4:18 PM -0800 12/5/08, Jason Todd Slack-Moehrle wrote:

How might I also parse and address like: SCOTTSDALE, AZ 85254

It has a comma and a space

-Jason

On Dec 5, 2008, at 4:02 PM, Jason Todd Slack-Moehrle wrote:


OK, making good learning progress today.

I have a string that is: Jason Slack

and I want it broken at the space so i get Jason and then Slack

I am looking at parse_str, but I dont get how to do it with a space. 
The example is using []=.


Then I want to assign like:

$fname = Jason;
$lname = Slack;

Any ideas?

-Jason


-Jason:

This is pretty basic stuff -- read the manuals about strings:

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

If you have shown that you've spent time reading and then have a 
problem, please post your question. But don't expect us to do your 
homework for you.


Cheers,

tedd



this is wrong on so many levels, but his name indicates that he's more 
of a delegator than a doer :p


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



[PHP] Parsing Strings

2008-12-05 Thread Jason Todd Slack-Moehrle

OK, making good learning progress today.

I have a string that is: Jason Slack

and I want it broken at the space so i get Jason and then Slack

I am looking at parse_str, but I dont get how to do it with a space.  
The example is using []=.


Then I want to assign like:

$fname = Jason;
$lname = Slack;

Any ideas?

-Jason

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



Re: [PHP] Parsing Strings

2008-12-05 Thread Jason Todd Slack-Moehrle


How might I also parse and address like: SCOTTSDALE, AZ 85254

It has a comma and a space

-Jason

On Dec 5, 2008, at 4:02 PM, Jason Todd Slack-Moehrle wrote:


OK, making good learning progress today.

I have a string that is: Jason Slack

and I want it broken at the space so i get Jason and then Slack

I am looking at parse_str, but I dont get how to do it with a space.  
The example is using []=.


Then I want to assign like:

$fname = Jason;
$lname = Slack;

Any ideas?

-Jason

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





AW: [PHP] Parsing Strings

2008-12-05 Thread Konrad Priemer
Hi,

Jason wrote:
 I have a string that is: Jason Slack
 and I want it broken at the space so i get Jason and then Slack

explode or split can do this.

$array = explode( , Jason Slack);

Array
(
[0] = Jason
[1] = Slack
)

Greetings from Stuttgart

Conny


---
Firma Konrad Priemer
Onlinedienste  Webdesign

Kirchheimer Straße 116, D-70619 Stuttgart
Tel. 0711-50420416, FAX 0711-50420417, VOIP 0711-50888660
eMail: mailto:[EMAIL PROTECTED] - Internet:
http://www.cp-onlinedienste.de
---
Aktuelles Projekt: http://www.tierische-events.de - Veranstaltungen für
(oder mit) Mensch, Hund, Katze und Pferd

 

__ Hinweis von ESET NOD32 Antivirus, Signaturdatenbank-Version 3667
(20081205) __

E-Mail wurde geprüft mit ESET NOD32 Antivirus.

http://www.eset.com
 


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



Re: AW: [PHP] Parsing Strings

2008-12-05 Thread Jason Todd Slack-Moehrle


Konrad,

On Dec 5, 2008, at 4:22 PM, Konrad Priemer wrote:


$array = explode( , Jason Slack);


Awesome, thanks, yup that does it.

Can you explain how to do an address now into City, State, Zip

Like: cortland, ny 13045

It has a comma and a space!

-Jason


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



AW: AW: [PHP] Parsing Strings

2008-12-05 Thread Konrad Priemer
Hi,

On Sa 06.12.2008 01:30 Jason wrote:

 Can you explain how to do an address now into City, State, Zip
 Like: cortland, ny 13045

Test this:

$string = cortland, ny 13045;
$search = array(, , ,); # if there is no space after the comma, we make
this ;-)
$replace = array( ,  );
$newString = str_replace($search, $replace, $string);
$array = explode( , $newString);

--
Old String: cortland, ny 13045
New String: cortland ny 13045

Array
(
[0] = cortland
[1] = ny
[2] = 13045
)
---

Regards from Stuttgart

Conny


PS: Sorry about my perfect english
 

__ Hinweis von ESET NOD32 Antivirus, Signaturdatenbank-Version 3667
(20081205) __

E-Mail wurde gepruft mit ESET NOD32 Antivirus.

http://www.eset.com
 


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



Re: AW: [PHP] Parsing Strings

2008-12-05 Thread Jason Todd Slack-Moehrle

Conny,


Can you explain how to do an address now into City, State, Zip
Like: cortland, ny 13045



$string = cortland, ny 13045;
$search = array(, , ,);
$replace = array( ,  );
$newString = str_replace($search, $replace, $string);
$array = explode( , $newString);


Ah ha! Nice that makes sense, why did I not think of that!

-Jason

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



AW: [PHP] Parsing Strings

2008-12-05 Thread Konrad Priemer
Oups, sorry

 

mistake by copy  paste ;-)

 

On Sa 06.12.2008 01:30 Jason wrote:

 

 Can you explain how to do an address now into City, State, Zip

 Like: cortland, ny 13045

 

 

$string = cortland, ny 13045;

$search = array(, , ,);

$replace = array( ,  );

$newString = str_replace($search, $replace, $string); $array = explode( ,
$newString);

 

 

Regards from Stuttgart

 

Conny

 

 

PS: Sorry about my perfect english



Re: [PHP] Parsing XML

2008-12-01 Thread Peter Ford
Per Jessen wrote:
 Ashley Sheridan wrote:
 
 On Fri, 2008-11-28 at 10:15 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:

 Do any of you have a copy of this extension, or failing that, a
 suggestion of how I can parse XML files without having to install
 anything on the remote server, as I do not have that level off
 access to it.
 Parsing XML is best done with XSL - if that's out of the question,
 you're in for a difficult time.


 /Per Jessen, Zürich


 XSL will only allow me to convert it into a different document format,
 which is not what I want as I need to keep a local copy of information
 in a database for searching and sorting purposes. Nathans class allows
 me to have the entire document put into an array tree, which is fine
 for what I need so far.
 
 That's cool, but XSL is still the more appropriate tool IMO.  It does
 exactly what you need - it parses and validates the XML document,
 allows you to extract the bits you need and in virtually any format you
 need - which could be a text document with SQL statements for piping to
 mysql. 
 
 
 /Per Jessen, Zürich
 

I'm with you on this, Per.
You could even use the XSL to construct a bunch of PHP which could be eval'd or
just read in as an include.
Or better yet, if you use the XSL classes, you can register PHP functions and
then call them within your XSL directly. That could potentially handle the
validation you required, and even do the database inserts.

I'm looking into using something like that on a project I'm currently working
on: maybe I can come up with some examples in a couple of days...

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Parsing XML

2008-12-01 Thread Per Jessen
Peter Ford wrote:

 Per Jessen wrote:
 
 That's cool, but XSL is still the more appropriate tool IMO.  It does
 exactly what you need - it parses and validates the XML document,
 allows you to extract the bits you need and in virtually any format
 you need - which could be a text document with SQL statements for
 piping to mysql.
 
 
 /Per Jessen, Zürich
 
 
 I'm with you on this, Per.
 You could even use the XSL to construct a bunch of PHP which could be
 eval'd or just read in as an include.
 Or better yet, if you use the XSL classes, you can register PHP
 functions and then call them within your XSL directly. That could
 potentially handle the validation you required, and even do the
 database inserts.

Yep, that occured to me too. I think XSL can even do quite a bit of the
validation too.

 I'm looking into using something like that on a project I'm currently
 working on: maybe I can come up with some examples in a couple of
 days...

Here's one easy example -

we generate monthly reports for our customers based on the activities of
the most recent month.  The template is an OpenOffice document (well,
several in different languages), which is merged with the activity data
to produce the report in OOo format.  The data is extracted and
formatted as XML. 
The process looks roughly like this:

OOo:template + XML:data - apply XSL - OOo document.  (We then turn the
final OOo document into a PDF which is emailed).  

Of course the same could be achieved using PHP, but instead of a neat
XSL stylesheet, I would have a pile of custom PHP code.

IMO, when you have a need to parse XML or otherwise extract data from
XML, you need a really good reason to disregard XSL.  The only really
good reason I've heard so far was lack of XSL skills, which could be a
real issue.  The learning curve IS quite steep. 


/Per Jessen, Zürich


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



Re: [PHP] Parsing XML

2008-12-01 Thread Ashley Sheridan
On Mon, 2008-12-01 at 11:28 +0100, Per Jessen wrote:
 Peter Ford wrote:
 
  Per Jessen wrote:
  
  That's cool, but XSL is still the more appropriate tool IMO.  It does
  exactly what you need - it parses and validates the XML document,
  allows you to extract the bits you need and in virtually any format
  you need - which could be a text document with SQL statements for
  piping to mysql.
  
  
  /Per Jessen, Zürich
  
  
  I'm with you on this, Per.
  You could even use the XSL to construct a bunch of PHP which could be
  eval'd or just read in as an include.
  Or better yet, if you use the XSL classes, you can register PHP
  functions and then call them within your XSL directly. That could
  potentially handle the validation you required, and even do the
  database inserts.
 
 Yep, that occured to me too. I think XSL can even do quite a bit of the
 validation too.
 
  I'm looking into using something like that on a project I'm currently
  working on: maybe I can come up with some examples in a couple of
  days...
 
 Here's one easy example -
 
 we generate monthly reports for our customers based on the activities of
 the most recent month.  The template is an OpenOffice document (well,
 several in different languages), which is merged with the activity data
 to produce the report in OOo format.  The data is extracted and
 formatted as XML. 
 The process looks roughly like this:
 
 OOo:template + XML:data - apply XSL - OOo document.  (We then turn the
 final OOo document into a PDF which is emailed).  
 
 Of course the same could be achieved using PHP, but instead of a neat
 XSL stylesheet, I would have a pile of custom PHP code.
 
 IMO, when you have a need to parse XML or otherwise extract data from
 XML, you need a really good reason to disregard XSL.  The only really
 good reason I've heard so far was lack of XSL skills, which could be a
 real issue.  The learning curve IS quite steep. 
 
 
 /Per Jessen, Zürich
 
 
I still disagree, as using XSL is essentially converting the XML to
another format, which is then being used by PHP. XSL is great for some
tasks, but for this, I think having a good PHP XMLDoc (or similar type
of) class is better.

On a slightly aside note though, how would you apply the XSL to the XML
using PHP? I know that you can have the stylesheet (XSL) called in from
within the XML document itself, but without being able to change that
XML document, how else can it be done? This could be quite useful to me
in the future.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Parsing XML

2008-12-01 Thread Per Jessen
Ashley Sheridan wrote:

 I still disagree, as using XSL is essentially converting the XML to
 another format, 

Which is all you're doing when you're extracting parts of an XML
document.  

 which is then being used by PHP. XSL is great for some tasks, but for
 this, I think having a good PHP XMLDoc (or similar type of) class is
 better. 

Ash, I'd really like to hear you argue why you think so.

I can't help thinking it's a bit like saying I know there is a compiler
for C-code, but I prefer to convert to assembler by using PHP.  I know
it's not quite that bad, but I hope you get my point.

 On a slightly aside note though, how would you apply the XSL to the
 XML using PHP? 

Roughly like this:  (this is from a project I'm currently working on).

--
// create the xslt processor object
if ( FALSE===($xp=new XSLTProcessor()) ) { print unable to create xslt
engine; return FALSE; }

// Load the XML source
$xml=new DOMDocument;
$xml-loadXML($list);

// then load the XSL stylesheet
$xsl=new DOMDocument;
$xsl-load('getfilebypos.xsl');

// attach the stylesheet
$xp-importStyleSheet($xsl);

$pos=$_GET['pos'];
$xp-setParameter('', array('pos' = $_GET['pos']) );

$file=$xp-transformToXML($xml);


$file in this case is just a single filename, no XML.  My input data has
a list of filenames, the 'pos' argument from the URI identifies one I
need to process.


/Per Jessen, Zürich


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



Re: [PHP] Parsing XML

2008-12-01 Thread Ashley Sheridan
On Mon, 2008-12-01 at 21:35 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:
 
  I still disagree, as using XSL is essentially converting the XML to
  another format, 
 
 Which is all you're doing when you're extracting parts of an XML
 document.  
 
  which is then being used by PHP. XSL is great for some tasks, but for
  this, I think having a good PHP XMLDoc (or similar type of) class is
  better. 
 
 Ash, I'd really like to hear you argue why you think so.
 
 I can't help thinking it's a bit like saying I know there is a compiler
 for C-code, but I prefer to convert to assembler by using PHP.  I know
 it's not quite that bad, but I hope you get my point.
 
  On a slightly aside note though, how would you apply the XSL to the
  XML using PHP? 
 
 Roughly like this:  (this is from a project I'm currently working on).
 
 --
 // create the xslt processor object
 if ( FALSE===($xp=new XSLTProcessor()) ) { print unable to create xslt
 engine; return FALSE; }
 
 // Load the XML source
 $xml=new DOMDocument;
 $xml-loadXML($list);
 
 // then load the XSL stylesheet
 $xsl=new DOMDocument;
 $xsl-load('getfilebypos.xsl');
 
 // attach the stylesheet
 $xp-importStyleSheet($xsl);
 
 $pos=$_GET['pos'];
 $xp-setParameter('', array('pos' = $_GET['pos']) );
 
 $file=$xp-transformToXML($xml);
 
 
 $file in this case is just a single filename, no XML.  My input data has
 a list of filenames, the 'pos' argument from the URI identifies one I
 need to process.
 
 
 /Per Jessen, Zürich
 
 
So here you're advocating loading the XML document into PHP to add an
element, then convert the XML into something else, for PHP to read back
in (not forgetting my original question said I need PHP to do some
operations on the XML.) Do you see why I just wanted a way to extract
the parts of the XML document I needed? This example is actually making
something unnecessarily complex just because XSL is deemed to be the
best way to work with XML.

I'm not saying that XSL is a bad thing, I've used it many times before
to convert various document formats, I just think that for what I
needed, XSL doesn't really suit the task at hand.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Parsing XML

2008-12-01 Thread Per Jessen
Ashley Sheridan wrote:

 Roughly like this:  (this is from a project I'm currently working
 on).
 
 --
 // create the xslt processor object
 if ( FALSE===($xp=new XSLTProcessor()) ) { print unable to create
 xslt engine; return FALSE; }
 
 // Load the XML source
 $xml=new DOMDocument;
 $xml-loadXML($list);
 
 // then load the XSL stylesheet
 $xsl=new DOMDocument;
 $xsl-load('getfilebypos.xsl');
 
 // attach the stylesheet
 $xp-importStyleSheet($xsl);
 
 $pos=$_GET['pos'];
 $xp-setParameter('', array('pos' = $_GET['pos']) );
 
 $file=$xp-transformToXML($xml);
 
 
 $file in this case is just a single filename, no XML.  My input data
 has a list of filenames, the 'pos' argument from the URI identifies
 one I need to process.
 
 
 /Per Jessen, Zürich
 
 
 So here you're advocating loading the XML document into PHP to add an
 element, then convert the XML into something else, for PHP to read
 back in (not forgetting my original question said I need PHP to do
 some operations on the XML.) 

No, not at all.  1) no element is added, 2) the document is not
loaded 'into' PHP and 3) PHP 'reads back' output of about 30 bytes (a
filename + path). 
None of the XSL+XML happens inside of PHP - it's done through the XSL
extension which is essentially all calls to libxslt. 

 Do you see why I just wanted a way to extract the parts of the XML
 document I needed? This example is actually making something
 unnecessarily complex just because XSL is deemed to be the best way to
 work with XML. 

Ash, my example above extracts a single element (specified by 'pos')
from an XML-document - it's all done by a standards-compliant XSLT
style-sheet, and very effectively so.  The 8 lines of PHP code to
invoke the XSL conversion are virtually 'standard' too.  I'm having a
hard time appreciating why that is better done by combining
somebodyelses custom code with your own custom code.

 I'm not saying that XSL is a bad thing, I've used it many times before
 to convert various document formats, I just think that for what I
 needed, XSL doesn't really suit the task at hand.

I understand what you're saying, I just haven't heard a good argument
yet.

Gotta go watch Dr. House on the telly now.  I'll be back tomorow
morning.


/Per Jessen, Zürich


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



Re: [PHP] Parsing XML

2008-12-01 Thread Nathan Rixham

Per Jessen wrote:

Ashley Sheridan wrote:

[/snip] :p

XSL(T)
an xslt processor, along with an XSLT stylesheet, should be used to 
transform XML documents in to other XML, human readable or structured 
documents.


DOM
a class implementing the DOM interface should be used to traverse, 
analyse and extract information from an HTML or valid XML document for 
use in a computer program or to convert values to there primitive 
counterparts.


E4X
ideally E4X should be used where available as this provides native XML 
support, treating xml documents as primitive types and thus providing a 
faster, more acceptable way of using XML as building blocks in a 
computer program.


PHP Support
As far as I am aware PHP does not have any kind of supoort for 
ECMAScript let alone E4X so this can be removed from the discussion as 
quickly as it was entered. Leaving just XSL and DOM.


Non programmatic XML usage:
For all non programatic usage of XML documents (ie transforming the 
document in to html, a human readable document or another xml structure) 
then XSLT should be used.

Examples:
-Integrating the data from an RSS feed into an (X)HTML page and 
outputing it to a client application (non persistant stuctured document)
-Converting an XML Packet into an OOo document and saving it in a file 
system (persistant stuctured document)


Programmatic XML Usage:
For all programmatic usage of XML, when you need to take the data from 
an XML document and use node or attribute values in a program, then the 
DOM API should be used.

Examples:
-Extracting the structured object data encapsulated in a SOAP response 
and using it to instantiate a class for further usage. (non persitant 
structured data for use by a computer program)
-Converting the data values in a structured XML document, (lets say from 
the WOW Armory), into primitive values and then persiting the data into 
database tables. (persitant structured data for use by a computer program)


Grey Areas:
If you are using an ORM which uses XML schemas to define data objects 
then xslt may be the more appropriate choice, this would probably incur 
an extra XSL transformation to then convert the ORM's schema into an object.
One could argue that XSLT could be used to transform the XML document in 
to an SQL string, however this would not allow (or certainly limited 
allowance of) programatic manipulation / validation of the data prior to 
 injection into the SQL string.


Alternatives:
Regex or string parsing on an XML document can often lead to far faster 
but less reliable extraction of data for use in a script, probably so 
common in PHP as it's loosley typed language :p Obviously though if the 
XML document structre changes, you're pretty much stuffed - thus any 
form of native or strongly typed support is a far better option.


Suggestion:
Ashley, TBH the approach I'd take (if I had time) would be to create 
class(es) for the data, then create XML documents representing the 
object structure of each class, write methods using the DOM API to 
extract data from my XML documents and instatiate the class(es) with it. 
At this point I'd have an app that need never change. Then I'd drop in a 
simple XSLT stylesheet to transform the remote XML document in to my 
local structured xml documents and use the XSL processor to run this 
transform. Thus if ever the remote document structure changed all I'd 
have to do is quickly edit the XSLT stylesheet.


But whatever you're cool with, a simple regex xml to array convertor is 
normally the fastest and most transportable way of doing this (ie it'll 
generally work on php 4 and 5 on any server); and when you're not using 
a pre-compiled language you need to give much weight to these things.


Regards!

Nath

[omg i must be bored]

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



Re: [PHP] Parsing XML

2008-11-29 Thread Ashley Sheridan
On Fri, 2008-11-28 at 20:39 +0100, Per Jessen wrote:
 Andrew Ballard wrote:
 
  XSL will only allow me to convert it into a different document
  format, which is not what I want as I need to keep a local copy of
  information in a database for searching and sorting purposes. Nathans
  class allows me to have the entire document put into an array tree,
  which is fine for what I need so far.
 
 
  Ash
  www.ashleysheridan.co.uk
  
  A bit over the top, but you could always use XSL to turn it into CSV. 
   LOL
  
  Andrew
 
 Not over the top at all if your database understands CSV.  I think it is
 very odd that no-one else is advocating XSL in this case.  Extracting
 information from an XML file is just another way of converting it,
 which is exactly what XSL is good at.  I can't imagine how using a pile
 of custom PHP code is going to be more efficient than writing a simple
 XSL stylesheet according to recognised standards etc.  Just my opinion
 of course. 
 
 
 /Per Jessen, Zürich
 
 
That would destroy the relationship of the data, as it id in no
structure that would be easy to port to a CSV format.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Parsing XML

2008-11-28 Thread Per Jessen
Ashley Sheridan wrote:

 Do any of you have a copy of this extension, or failing that, a
 suggestion of how I can parse XML files without having to install
 anything on the remote server, as I do not have that level off access
 to it.

Parsing XML is best done with XSL - if that's out of the question,
you're in for a difficult time. 


/Per Jessen, Zürich


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



Re: [PHP] Parsing XML

2008-11-28 Thread Ashley Sheridan
On Fri, 2008-11-28 at 10:15 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:
 
  Do any of you have a copy of this extension, or failing that, a
  suggestion of how I can parse XML files without having to install
  anything on the remote server, as I do not have that level off access
  to it.
 
 Parsing XML is best done with XSL - if that's out of the question,
 you're in for a difficult time. 
 
 
 /Per Jessen, Zürich
 
 
XSL will only allow me to convert it into a different document format,
which is not what I want as I need to keep a local copy of information
in a database for searching and sorting purposes. Nathans class allows
me to have the entire document put into an array tree, which is fine for
what I need so far.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Parsing XML

2008-11-28 Thread Per Jessen
Ashley Sheridan wrote:

 On Fri, 2008-11-28 at 10:15 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:
 
  Do any of you have a copy of this extension, or failing that, a
  suggestion of how I can parse XML files without having to install
  anything on the remote server, as I do not have that level off
  access to it.
 
 Parsing XML is best done with XSL - if that's out of the question,
 you're in for a difficult time.
 
 
 /Per Jessen, Zürich
 
 
 XSL will only allow me to convert it into a different document format,
 which is not what I want as I need to keep a local copy of information
 in a database for searching and sorting purposes. Nathans class allows
 me to have the entire document put into an array tree, which is fine
 for what I need so far.

That's cool, but XSL is still the more appropriate tool IMO.  It does
exactly what you need - it parses and validates the XML document,
allows you to extract the bits you need and in virtually any format you
need - which could be a text document with SQL statements for piping to
mysql. 


/Per Jessen, Zürich


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



Re: [PHP] Parsing XML

2008-11-28 Thread Ashley Sheridan
On Fri, 2008-11-28 at 13:14 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:
 
  On Fri, 2008-11-28 at 10:15 +0100, Per Jessen wrote:
  Ashley Sheridan wrote:
  
   Do any of you have a copy of this extension, or failing that, a
   suggestion of how I can parse XML files without having to install
   anything on the remote server, as I do not have that level off
   access to it.
  
  Parsing XML is best done with XSL - if that's out of the question,
  you're in for a difficult time.
  
  
  /Per Jessen, Zürich
  
  
  XSL will only allow me to convert it into a different document format,
  which is not what I want as I need to keep a local copy of information
  in a database for searching and sorting purposes. Nathans class allows
  me to have the entire document put into an array tree, which is fine
  for what I need so far.
 
 That's cool, but XSL is still the more appropriate tool IMO.  It does
 exactly what you need - it parses and validates the XML document,
 allows you to extract the bits you need and in virtually any format you
 need - which could be a text document with SQL statements for piping to
 mysql. 
 
 
 /Per Jessen, Zürich
 
 
Possibly, but I wouldn't want to trust the end content in such a way;
I'd like to check out the values first. All-in-all, I think XSL is not
the right tool for the job in this case, but it is A way of doing it. 


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Parsing XML

2008-11-28 Thread Andrew Ballard
On Fri, Nov 28, 2008 at 5:45 AM, Ashley Sheridan
[EMAIL PROTECTED] wrote:
 On Fri, 2008-11-28 at 10:15 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:

  Do any of you have a copy of this extension, or failing that, a
  suggestion of how I can parse XML files without having to install
  anything on the remote server, as I do not have that level off access
  to it.

 Parsing XML is best done with XSL - if that's out of the question,
 you're in for a difficult time.


 /Per Jessen, Zürich


 XSL will only allow me to convert it into a different document format,
 which is not what I want as I need to keep a local copy of information
 in a database for searching and sorting purposes. Nathans class allows
 me to have the entire document put into an array tree, which is fine for
 what I need so far.


 Ash
 www.ashleysheridan.co.uk

A bit over the top, but you could always use XSL to turn it into CSV.   LOL

Andrew


Re: [PHP] Parsing XML

2008-11-28 Thread Per Jessen
Andrew Ballard wrote:

 XSL will only allow me to convert it into a different document
 format, which is not what I want as I need to keep a local copy of
 information in a database for searching and sorting purposes. Nathans
 class allows me to have the entire document put into an array tree,
 which is fine for what I need so far.


 Ash
 www.ashleysheridan.co.uk
 
 A bit over the top, but you could always use XSL to turn it into CSV. 
  LOL
 
 Andrew

Not over the top at all if your database understands CSV.  I think it is
very odd that no-one else is advocating XSL in this case.  Extracting
information from an XML file is just another way of converting it,
which is exactly what XSL is good at.  I can't imagine how using a pile
of custom PHP code is going to be more efficient than writing a simple
XSL stylesheet according to recognised standards etc.  Just my opinion
of course. 


/Per Jessen, Zürich


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



[PHP] Parsing XML

2008-11-27 Thread Ashley Sheridan
Hi All,

I've run into a bit of a problem. I need to parse some fairly detailed
XML files from a remote website. I'm pulling in the remote XML using
curl, and that bit is working fine. The smaller XML documents were easy
to parse with regular expressions, as I only needed  bit of information
out of them.

The live server I'm eventually putting this onto only has domxml for
working with XML. I've been trying to find the pecl extension for this
to install on my local machine, but the pecl.php.net site is a bit
nerfed for this extension (I'm getting a file not found error message.)

Do any of you have a copy of this extension, or failing that, a
suggestion of how I can parse XML files without having to install
anything on the remote server, as I do not have that level off access to
it.

Thanks
Ash
www.ashleysheridan.co.uk


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



[PHP] Parsing out excel's .xls textboxes?

2008-11-13 Thread Nitsan Bin-Nun
Hi,
I have an excel parser I found out on the net a while ago.
It does a really great job untill now.
I need to parse out an excel file (.xls) with excel's textboxes in it,
I want to fetch the textboxes content from the .xls somehow.

I have no idea where to look out for this,
I have even considered trying to understand the structure of a common .xls
file by myself but I even don't know what direction I should be heading to!

If you have any idea, suggestion, anything that might help, feel free to
come up and surprise me ;)

Thanks in Advance,
Nitsan


Re: [PHP] Parsing out excel's .xls textboxes?

2008-11-13 Thread Ashley Sheridan
On Fri, 2008-11-14 at 00:45 +0200, Nitsan Bin-Nun wrote:
 Hi,
 I have an excel parser I found out on the net a while ago.
 It does a really great job untill now.
 I need to parse out an excel file (.xls) with excel's textboxes in it,
 I want to fetch the textboxes content from the .xls somehow.
 
 I have no idea where to look out for this,
 I have even considered trying to understand the structure of a common .xls
 file by myself but I even don't know what direction I should be heading to!
 
 If you have any idea, suggestion, anything that might help, feel free to
 come up and surprise me ;)
 
 Thanks in Advance,
 Nitsan
First question to ask; which version of the format is the file?


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Parsing out excel's .xls textboxes?

2008-11-13 Thread Nitsan Bin-Nun
It is binary file, saved from office 2003.
There is no way of changing the office version (so I can save it as .xml of
something) so I have to figure out how to parse these textboxes.

Nitsan

On 11/14/08, Ashley Sheridan [EMAIL PROTECTED] wrote:

 On Fri, 2008-11-14 at 00:45 +0200, Nitsan Bin-Nun wrote:
  Hi,
  I have an excel parser I found out on the net a while ago.
  It does a really great job untill now.
  I need to parse out an excel file (.xls) with excel's textboxes in it,
  I want to fetch the textboxes content from the .xls somehow.
 
  I have no idea where to look out for this,
  I have even considered trying to understand the structure of a common
 .xls
  file by myself but I even don't know what direction I should be heading
 to!
 
  If you have any idea, suggestion, anything that might help, feel free to
  come up and surprise me ;)
 
  Thanks in Advance,
  Nitsan
 First question to ask; which version of the format is the file?


 Ash
 www.ashleysheridan.co.uk




Re: [PHP] Parsing URLs

2008-10-28 Thread Yeti
One could also abuse basename and pathinfo.
Works in PHP4+

?php
$uri = 'http://www.domain.com/page/file/';
$pathinfo = pathinfo($uri);
$webpageaccess = array();
$webpageaccess[1] = $webpageaccess[2] = '';
if (isset($pathinfo['basename'])) $webpageaccess[1] = $pathinfo['basename'];
if (isset($pathinfo['dirname'])) $webpageaccess[2] =
basename($pathinfo['dirname']);
//var_dump($webpageaccess);
?

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



[PHP] Parsing URLs

2008-10-27 Thread Ron Piggott
I would like to parse the URLs in the values after the domain name.  

The URLs are the results of mod re-write statements.  

Example 1:

http://www.domain.com/page/file/

The desired results would be: 
$web_page_access[1] = file

Example 2:

http://www.domain.com/page/file/2/ 

The desired results would be:
$web_page_access[1] = file
$web_page_access[2] = 2

Any help please?

Ron


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



Re: [PHP] Parsing URLs

2008-10-27 Thread Eric Butera
On Mon, Oct 27, 2008 at 10:04 PM, Ron Piggott
[EMAIL PROTECTED] wrote:
 I would like to parse the URLs in the values after the domain name.

 The URLs are the results of mod re-write statements.

 Example 1:

 http://www.domain.com/page/file/

 The desired results would be:
 $web_page_access[1] = file

 Example 2:

 http://www.domain.com/page/file/2/

 The desired results would be:
 $web_page_access[1] = file
 $web_page_access[2] = 2

 Any help please?

 Ron


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



// $uri = htmlspecialchars($SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8');
$uri = htmlspecialchars('/page/file/2/', ENT_QUOTES, 'UTF-8');;
$uri = trim($uri, /);
$parts = explode(/, $uri);
var_dump($parts);

or use parse_url to get down to the bits you need.

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



[PHP] parsing form with a website question...

2008-08-14 Thread bruce
Hi guys...

Got a question that I figured I'd ask before I reinvent the wheel.

A basic website has a form, or multiple forms.  within the form, there might
be multiple elements (lists/select statements, etc...). each item would have
a varname, which would in turn be used as part of the form action, to create
the entire query...

sort of like:
form action=test.php?
 option
  name=foo
  foo=1
  foo=2
  foo=3
  foo=4
 /option

 option
  name=cat
  cat=1
  cat=2
  cat=3
 /option
/form

so you'd get the following urls in this psuedo example:
 test.php?foo=1cat=1
 test.php?foo=1cat=2
 test.php?foo=1cat=3
 test.php?foo=2cat=1
 test.php?foo=2cat=2
 test.php?foo=2cat=3
 test.php?foo=3cat=1
 test.php?foo=3cat=2
 test.php?foo=3cat=3
 test.php?foo=4cat=1
 test.php?foo=4cat=2
 test.php?foo=4cat=3

i'm looking for an app that has the ability to parse any given form on a
web page, returning the complete list of possible url combinations based on
the underlying elements that make up/define the form...

anybody ever seen anything remotely close to this...???

i've been research crawlers, thinking that this kind of functionality would
already exist, but so far, no luck!

thanks




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

Re: [PHP] parsing form with a website question...

2008-08-14 Thread Robert Cummings
On Thu, 2008-08-14 at 15:47 -0700, bruce wrote:
 Hi guys...
 
 Got a question that I figured I'd ask before I reinvent the wheel.
 
 A basic website has a form, or multiple forms.  within the form, there might
 be multiple elements (lists/select statements, etc...). each item would have
 a varname, which would in turn be used as part of the form action, to create
 the entire query...
 
 sort of like:
 form action=test.php?
  option
   name=foo
   foo=1
   foo=2
   foo=3
   foo=4
  /option
 
  option
   name=cat
   cat=1
   cat=2
   cat=3
  /option
 /form
 
 so you'd get the following urls in this psuedo example:
  test.php?foo=1cat=1
  test.php?foo=1cat=2
  test.php?foo=1cat=3
  test.php?foo=2cat=1
  test.php?foo=2cat=2
  test.php?foo=2cat=3
  test.php?foo=3cat=1
  test.php?foo=3cat=2
  test.php?foo=3cat=3
  test.php?foo=4cat=1
  test.php?foo=4cat=2
  test.php?foo=4cat=3
 
 i'm looking for an app that has the ability to parse any given form on a
 web page, returning the complete list of possible url combinations based on
 the underlying elements that make up/define the form...
 
 anybody ever seen anything remotely close to this...???
 
 i've been research crawlers, thinking that this kind of functionality would
 already exist, but so far, no luck!

A little algorithm analysis would learn you that to do so would require
storage space on an exponential scale... as such you won't find it.
Also, what would you put into text/textarea fields? I've heard Google
has begun experiments to index the deep web, but they just take
somewhat educated guesses at filling in forms, not at expanding the
exponential result set. For a simple analysis of the problem. Take 2
select fields with 2 options each... you have 4 possible outcomes (2 *
2). Now take 3 selects lists with 3 items, 4 items, and 5 items. You now
have 60 possible outcomes. From this it is easy to see the relation ship
is a * b * c * ... * x. So take a form with 10 select fields each with
10 items. That evaluates to 10^10 = 100. In other words, with a
mere 10 drop down selects each with 10 items, the solution space
consists of 10 billion permutations. Now lets say each item costs
exactly 1 byte to store the answer, and so you need 10 bytes to store
one particular solution set. That's 100 billion bytes AKA 100 metric
gigabytes... remember that was just 1 form.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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



RE: [PHP] parsing form with a website question...

2008-08-14 Thread bruce
rob,

i'm fully aware of the issues, and for the targeted sites that i'm focusing
on, i can employ strategies to prune the tree... but the overall issue is
that i'm looking for a tool/app/process that does what i've described.

the basic logic is that the app needs to use a config file, and that the app
should somehow find the requisite form using perhaps xpath, in combination
with some kind of pattern recognition/regex functionality...

once the app has the form, it can then get the underlying stuff
(selects/lists/items, etc.. which will form the basis for the querystrings
to the form action...

ain't life grand!!

thanks...



-Original Message-
From: Robert Cummings [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 14, 2008 4:57 PM
To: bruce
Cc: php-general@lists.php.net
Subject: Re: [PHP] parsing form with a website question...


On Thu, 2008-08-14 at 15:47 -0700, bruce wrote:
 Hi guys...

 Got a question that I figured I'd ask before I reinvent the wheel.

 A basic website has a form, or multiple forms.  within the form, there
might
 be multiple elements (lists/select statements, etc...). each item would
have
 a varname, which would in turn be used as part of the form action, to
create
 the entire query...

 sort of like:
 form action=test.php?
  option
   name=foo
   foo=1
   foo=2
   foo=3
   foo=4
  /option

  option
   name=cat
   cat=1
   cat=2
   cat=3
  /option
 /form

 so you'd get the following urls in this psuedo example:
  test.php?foo=1cat=1
  test.php?foo=1cat=2
  test.php?foo=1cat=3
  test.php?foo=2cat=1
  test.php?foo=2cat=2
  test.php?foo=2cat=3
  test.php?foo=3cat=1
  test.php?foo=3cat=2
  test.php?foo=3cat=3
  test.php?foo=4cat=1
  test.php?foo=4cat=2
  test.php?foo=4cat=3

 i'm looking for an app that has the ability to parse any given form on a
 web page, returning the complete list of possible url combinations based
on
 the underlying elements that make up/define the form...

 anybody ever seen anything remotely close to this...???

 i've been research crawlers, thinking that this kind of functionality
would
 already exist, but so far, no luck!

A little algorithm analysis would learn you that to do so would require
storage space on an exponential scale... as such you won't find it.
Also, what would you put into text/textarea fields? I've heard Google
has begun experiments to index the deep web, but they just take
somewhat educated guesses at filling in forms, not at expanding the
exponential result set. For a simple analysis of the problem. Take 2
select fields with 2 options each... you have 4 possible outcomes (2 *
2). Now take 3 selects lists with 3 items, 4 items, and 5 items. You now
have 60 possible outcomes. From this it is easy to see the relation ship
is a * b * c * ... * x. So take a form with 10 select fields each with
10 items. That evaluates to 10^10 = 100. In other words, with a
mere 10 drop down selects each with 10 items, the solution space
consists of 10 billion permutations. Now lets say each item costs
exactly 1 byte to store the answer, and so you need 10 bytes to store
one particular solution set. That's 100 billion bytes AKA 100 metric
gigabytes... remember that was just 1 form.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP


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



Re: [PHP] parsing form with a website question...

2008-08-14 Thread tedd

At 7:57 PM -0400 8/14/08, Robert Cummings wrote:

On Thu, 2008-08-14 at 15:47 -0700, bruce wrote:
-snip- That's 100 billion bytes AKA 100 metric
gigabytes... remember that was just 1 form.

Cheers,
Rob.


Killjoy.  :-)

He could have had a lot of fun figuring that out.

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] parsing form with a website question...

2008-08-14 Thread Chris

bruce wrote:

rob,

i'm fully aware of the issues, and for the targeted sites that i'm focusing
on, i can employ strategies to prune the tree... but the overall issue is
that i'm looking for a tool/app/process that does what i've described.

the basic logic is that the app needs to use a config file, and that the app
should somehow find the requisite form using perhaps xpath, in combination
with some kind of pattern recognition/regex functionality...

once the app has the form, it can then get the underlying stuff
(selects/lists/items, etc.. which will form the basis for the querystrings
to the form action...


Don't know of anything that does this off hand but it'd be a good 
project for a security check app :) See what values/options the form 
accepts and what it fails with..


--
Postgresql  php tutorials
http://www.designmagick.com/


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



Re: [PHP] parsing form with a website question...

2008-08-14 Thread Robert Cummings
On Thu, 2008-08-14 at 21:39 -0400, tedd wrote:
 At 7:57 PM -0400 8/14/08, Robert Cummings wrote:
 On Thu, 2008-08-14 at 15:47 -0700, bruce wrote:
 -snip- That's 100 billion bytes AKA 100 metric
 gigabytes... remember that was just 1 form.
 
 Cheers,
 Rob.
 
 Killjoy.  :-)
 
 He could have had a lot of fun figuring that out.

He was lookig for a premade solution... it didn't seem like he wanted to
figure it out :)

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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



[PHP] parsing text for special characters

2007-11-29 Thread Adam Williams
I've got an html form, and I have PHP parse the message variables for 
special characters so when I concatenate all off the message variables 
together, if a person has put in a '  or other special character, it 
won't break it when it used in mail($to, MMH Suggestion, $message, 
$headers);  below is my snippet of code, but is there a better way to 
parse the text for special characters.  what about if I were to have the 
$message inserted into a mysql field?  how would I need to handle 
special characters that way?


$need_message = $_POST['need_message'];

  function flash_encode($need_message)
  {
 $string = rawurlencode(utf8_encode($need_message));

 $string = str_replace(%C2%96, -, $need_message);
 $string = str_replace(%C2%91, %27, $need_message);
 $string = str_replace(%C2%92, %27, $need_message);
 $string = str_replace(%C2%82, %27, $need_message);
 $string = str_replace(%C2%93, %22, $need_message);
 $string = str_replace(%C2%94, %22, $need_message);
 $string = str_replace(%C2%84, %22, $need_message);
 $string = str_replace(%C2%8B, %C2%AB, $need_message);
 $string = str_replace(%C2%9B, %C2%BB, $need_message);

 return $need_message;
  }

//and then there are $topic_message, $fee_message, etc and they all get 
concatenated with

$message .= needs_message;
$message .= $topics_message;
$message .= $fee message;

//emails the $message
mail($to, MMH Suggestion, $message, $headers);

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



Re: [PHP] parsing text for special characters

2007-11-29 Thread mike
On 11/29/07, Adam Williams [EMAIL PROTECTED] wrote:
 I've got an html form, and I have PHP parse the message variables for
 special characters so when I concatenate all off the message variables
 together, if a person has put in a '  or other special character, it
 won't break it when it used in mail($to, MMH Suggestion, $message,
 $headers);  below is my snippet of code, but is there a better way to
 parse the text for special characters.  what about if I were to have the
 $message inserted into a mysql field?  how would I need to handle
 special characters that way?

htmlentities()
htmlspecialchars()

first i would run $message = filter_input(INPUT_POST, 'message',
FILTER_SANITIZE_STRING);

then probably $message = htmlspecialchars($message);

that should suffice. it depends i suppose. if you need to dump the
html as-is, or you want to encode it first. i don't trust anything
users submit though, so i encode it on output

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



Re: [PHP] parsing text for special characters

2007-11-29 Thread Jochem Maas
Adam Williams wrote:
 I've got an html form, and I have PHP parse the message variables for
 special characters so when I concatenate all off the message variables
 together, if a person has put in a '  or other special character, it

exactly how are ' and  special inside the body of an email message?

 won't break it when it used in mail($to, MMH Suggestion, $message,
 $headers);  below is my snippet of code, but is there a better way to
 parse the text for special characters.  what about if I were to have the

it's not 'parsing' - it's 'escaping', and how you escape depends on the context
in which the string is going to be used.

 $message inserted into a mysql field?  how would I need to handle
 special characters that way?

mysql_real_escape_string()

 
 $need_message = $_POST['need_message'];
 
   function flash_encode($need_message)
   {
  $string = rawurlencode(utf8_encode($need_message));
 
  $string = str_replace(%C2%96, -, $need_message);
  $string = str_replace(%C2%91, %27, $need_message);
  $string = str_replace(%C2%92, %27, $need_message);
  $string = str_replace(%C2%82, %27, $need_message);
  $string = str_replace(%C2%93, %22, $need_message);
  $string = str_replace(%C2%94, %22, $need_message);
  $string = str_replace(%C2%84, %22, $need_message);
  $string = str_replace(%C2%8B, %C2%AB, $need_message);
  $string = str_replace(%C2%9B, %C2%BB, $need_message);
 
  return $need_message;
   }

where is this function used and why would you 'flash encode' a string
destined for the body of an email?

 
 //and then there are $topic_message, $fee_message, etc and they all get
 concatenated with
 $message .= needs_message;

this line is wrong, unless 'needs_message' is actually a constant.

 $message .= $topics_message;
 $message .= $fee message;

this line is a parse error. have you actually tried to run your code?

 
 //emails the $message
 mail($to, MMH Suggestion, $message, $headers);

^-- why are these variables inside quotes?

 

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



[PHP] Parsing XML with DTD

2007-11-22 Thread Skip Evans

Hey all,

I've been asked if it's possible to parse XML 
files given a DTD file that describes the elements 
within it, so I've been looking through the docs 
at php.net.


So far I've found this:

http://us.php.net/manual/en/ref.xml.php

Which has some samples on, but nothing that I see 
will take a DTD file and parse the XML accordingly.


I'm thinking something like this is probably possible.

I'm still looking through the docs, but if anyone 
can point me in the right direction would be 
appreciated.


Thanks!
Skip

--
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison, WI 53703
608-250-2720
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and versatile
PHP/MySQL, AJAX  DHTML development framework.
http://phpenguin.bigskypenguin.com/

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



Re: [PHP] Parsing XML with DTD

2007-11-22 Thread Skip Evans

Hey Jochem  all,

Thanks much for this tip. I will check it out.

A little further reading looks like PEAR provides 
some XML and DTD capabilities? Anyone have any 
experience with this?


Also, the reason I asked about the DTD is that 
these XML files are really extensive, providing 
lots of varied info about literature, history, a 
whole ton of topics, so I thought parsing the DTD 
will be necessary to know what kinds of data I'm 
really looking at.


I'll check out Jochem's suggestion now, but would 
also like to hear if anyone has used PEAR, and 
also about the need for the DTD for big, 
complicated XML files.


Would it be helpful if I pasted one of the XML 
files to the list?


Thanks again!
Skip


Jochem Maas wrote:

Skip Evans wrote:

Hey all,

I've been asked if it's possible to parse XML files given a DTD file
that describes the elements within it, so I've been looking through the
docs at php.net.

So far I've found this:

http://us.php.net/manual/en/ref.xml.php

Which has some samples on, but nothing that I see will take a DTD file
and parse the XML accordingly.


use php5 and the DOM extension (not XML and not DOMXML):

http://us.php.net/manual/en/ref.dom.php


I'm thinking something like this is probably possible.

I'm still looking through the docs, but if anyone can point me in the
right direction would be appreciated.

Thanks!
Skip






--
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison, WI 53703
608-250-2720
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and versatile
PHP/MySQL, AJAX  DHTML development framework.
http://phpenguin.bigskypenguin.com/

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



  1   2   3   4   5   6   7   >