Re: [PHP] Re: Parsing a phrase

2010-12-12 Thread Rick Dwyer

I have it working now using preg_replace.

 --Rick


On Dec 12, 2010, at 3:50 PM, Rick Dwyer wrote:


Thanks Nathan.
The MySQL Match/Against will probably work well... but I would need  
to somehow add a "+" to the beginning of each word in the phrase so  
PHP will still be involved.



--Rick


On Dec 12, 2010, at 2:51 PM, Nathan Rixham wrote:


Rick Dwyer wrote:

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%" )


You may be better to use full text and MATCH for this, see:

http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html

However..

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.


There are many ways you can do this:

http://php.net/explode
http://php.net/str_split
http://php.net/preg_split

Many examples can be found on the above pages, and you're real  
solution depends on how many edge-cases you want to cover, but the  
above will cover most approaches :)


Best,

Nathan

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




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




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



Re: [PHP] Re: Parsing a phrase

2010-12-12 Thread Rick Dwyer

Thanks Nathan.
The MySQL Match/Against will probably work well... but I would need to  
somehow add a "+" to the beginning of each word in the phrase so PHP  
will still be involved.



 --Rick


On Dec 12, 2010, at 2:51 PM, Nathan Rixham wrote:


Rick Dwyer wrote:

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%" )


You may be better to use full text and MATCH for this, see:

http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html

However..

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.


There are many ways you can do this:

 http://php.net/explode
 http://php.net/str_split
 http://php.net/preg_split

Many examples can be found on the above pages, and you're real  
solution depends on how many edge-cases you want to cover, but the  
above will cover most approaches :)


Best,

Nathan

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




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



[PHP] Re: Parsing a phrase

2010-12-12 Thread Nathan Rixham

Rick Dwyer wrote:

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%" )


You may be better to use full text and MATCH for this, see:

http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html

However..

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.


There are many ways you can do this:

  http://php.net/explode
  http://php.net/str_split
  http://php.net/preg_split

Many examples can be found on the above pages, and you're real solution 
depends on how many edge-cases you want to cover, but the above will 
cover most approaches :)


Best,

Nathan

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



Re: [PHP] Re: Parsing of forms

2009-05-20 Thread Daniele Grillenzoni

On 20/05/2009 12.50, Ford, Mike wrote:

Humph! Yes, ok, I concede this point. I also bow to Daniele's need to
process forms designed by someone else with (not-PHP) in mind. Actually,
I can see the validity of both sides of the argument, and I teeter on
the fence as to whether  the [] method is "right" or not!! ;)



Teeter not, as I am not pushing for a retool of how $_POST and $_GET 
work, just maybe a new core function/global array that gets me the 
"pure" alternative.


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



Re: [PHP] Re: Parsing of forms

2009-05-20 Thread Andrew Ballard
On Wed, May 20, 2009 at 6:50 AM, Ford, Mike  wrote:
> On 19 May 2009 17:10, Andrew Ballard advised:
>>               var toppings = document.sundae.toppings;
>>                 // To work with PHP, the above line would
>> have to be changed:
>>                 // var toppings =
>> document.sundae.elements['toppings[]'];
>
> Actually, document.sundae['toppings[]'] is sufficient (because it is
> defined in JavaScript that a['b'] is always exactly equivalent to a.b).
>
> Cheers!
>
> Mike
>

True enough. I suppose it makes sense to just use the JavaScript array
notation syntax for accessing form elements all the time and not worry
about it any more.

I'll admit that when I first learned PHP3, it even seemed cool that
you could add elements to arrays (even nested or multi-dimensional
arrays) automatically by placing the appropriate square brackets in
the field name. At the time, having the language automatically create
variables for each of my form fields compared with what I had to do in
PERL seemed pretty cool too. ;-) I just thought it ridiculous the
first time I migrated a simple form processing script from PERL to PHP
that I had to change the HTML and the related JavaScript to be
compatible with PHP.

Andrew

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



Re: [PHP] Re: Parsing of forms

2009-05-20 Thread Raymond Irving
Hello,

Here's another quick solution that shouldn't add much overhead:

// get input 
$qry = 
'toppings=sprinkles&toppings=nuts&toppings=fudge&toppings=caramel&toppings=strawberries';
//$qry = $_SERVER['QUERY_STRING'];

// parser input
$qry = str_replace('&toppings=','&toppings[]=',$qry);
parse_str($qry,$get);

print_r($get);


__
Raymond Irving
Create Rich Ajax/PHP Web Apps Today!
Raxan PDI - http://raxanpdi.com/



--- On Wed, 5/20/09, Daniele Grillenzoni  wrote:

Yeah, and php://input should be able to handle $_POST, but custom 
functions ftl, the idea of having useless overhead for simple stuff like 
this makes me angry.




Re: [PHP] Re: Parsing of forms

2009-05-20 Thread Tom Worster
On 5/20/09 6:50 AM, "Ford, Mike"  wrote:

> Humph! Yes, ok, I concede this point. I also bow to Daniele's need to
> process forms designed by someone else with (not-PHP) in mind. Actually,
> I can see the validity of both sides of the argument, and I teeter on
> the fence as to whether  the [] method is "right" or not!! ;)

think of it this way: as it stands, php requires that php language elements
be placed in html documents.



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



RE: [PHP] Re: Parsing of forms

2009-05-20 Thread Ford, Mike
On 19 May 2009 17:10, Andrew Ballard advised:

> On Tue, May 19, 2009 at 10:11 AM, Ford, Mike
>  wrote:
>> On 19 May 2009 14:37, Daniele Grillenzoni advised:
>> 
>>> 
>>> My complaint is this: a I can have a select multiple with a normal
name,
>>> which is allowed by every spec, but PHP requires me to use [] in
order
>>> to properly retrieve the values.
>> 
>> I really don't understand the problem with this -- in fact, I find it
>> quite useful to distinguish inputs which may have only 1 value from
>> those which may be multi-valued. And it all depends on what you mean
by
>> a "normal" name, of course -- no current (X)HTML spec disallows [] as
>> part of a name attribute, so in that sense a name containing them
could
>> be seen as perfectly normal...!! ;) ;)
>> 
>> Can you explain why this is such a hang-up for you, as I haven't seen
>> anything in what you've posted so far to convince me it's any kind of
>> problem? 
>> 
>> Cheers!
>> 
>> Mike
>> 
> 
> I can't speak for the OP, but I've always thought it somewhat odd. An
> HTML form should be able to work correctly without modification
> regardless of the language that receives the input. As it is, it makes
> the HTML for a form implementation specific. You might be able to use
> ASP correctly process a form originally targeted toward PHP, but you
> could not similarly take a form designed for ASP and process it with
PHP
> without modification.

Humph! Yes, ok, I concede this point. I also bow to Daniele's need to
process forms designed by someone else with (not-PHP) in mind. Actually,
I can see the validity of both sides of the argument, and I teeter on
the fence as to whether  the [] method is "right" or not!! ;)

>   var toppings = document.sundae.toppings;
> // To work with PHP, the above line would
> have to be changed:
> // var toppings =
> document.sundae.elements['toppings[]'];

Actually, document.sundae['toppings[]'] is sufficient (because it is
defined in JavaScript that a['b'] is always exactly equivalent to a.b).

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: m.f...@leedsmet.ac.uk
Tel: +44 113 812 4730



To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



Re: [PHP] Re: Parsing of forms

2009-05-20 Thread Nathan Rixham

Daniele Grillenzoni wrote:

On 20/05/2009 2.45, Nathan Rixham wrote:

Daniele Grillenzoni wrote:

On 19/05/2009 18.09, Andrew Ballard wrote:

On Tue, May 19, 2009 at 10:11 AM, Ford, Mike
wrote:

On 19 May 2009 14:37, Daniele Grillenzoni advised:



My complaint is this: a I can have a select multiple with a
normal name,
which is allowed by every spec, but PHP requires me to use []
in order
to properly retrieve the values.


I really don't understand the problem with this -- in fact, I find it
quite useful to distinguish inputs which may have only 1 value from
those which may be multi-valued. And it all depends on what you 
mean by

a "normal" name, of course -- no current (X)HTML spec disallows [] as
part of a name attribute, so in that sense a name containing them 
could

be seen as perfectly normal...!! ;) ;)

Can you explain why this is such a hang-up for you, as I haven't seen
anything in what you've posted so far to convince me it's any kind of
problem?

Cheers!

Mike



I can't speak for the OP, but I've always thought it somewhat odd. An
HTML form should be able to work correctly without modification
regardless of the language that receives the input. As it is, it makes
the HTML for a form implementation specific. You might be able to use
ASP correctly process a form originally targeted toward PHP, but you
could not similarly take a form designed for ASP and process it with
PHP without modification.

It also impacts the use of client-side JavaScript. Consider a simple
page like this:

sundae.html
==



function countToppings() {
var totalToppings = 0;

var toppings = document.sundae.toppings;
// To work with PHP, the above line would have to be changed:
// var toppings = document.sundae.elements['toppings[]'];

if (toppings.length> 1) {
for (var i = 0; i< toppings.length; i++) {
if (toppings[i].checked) totalToppings++;
}
} else {
if (toppings.checked) totalToppings++
}

if (totalToppings == 0) {
confirm("Are you sure you don't want any toppings on your sundae?");
} else if (totalToppings> 3) {
alert("Wow! That's a lot of toppings!");
} else if (totalToppings == 1) {
alert("You only want one topping.");
} else {
alert("You have selected " + totalToppings + " toppings! Yummy!");
}
}






Toppings
 sprinkles
 nuts
 fudge
 caramel
 strawberries








The above form, if submitted, could build a perfectly valid query
string of
"?toppings=sprinkles&toppings=nuts&toppings=fudge&toppings=caramel&toppings=strawberries". 




In the grand scheme of things, these are just subtleties that can
easily be handled. Since my first major experience with a web language
was PHP (after a very brief dabble in PERL) before I took a turn at
ASP/VBScript, I'm used to it and it isn't a "hang-up" for me. But
something about it never seemed quite "right" to me either. :-)

Andrew


Andrew captured perfectly what I meant.

"?toppings=sprinkles&toppings=nuts&toppings=fudge&toppings=caramel&toppings=strawberries" 


is a valid querystring that php sort of fail at understanding.

I have nothing against supplying a string/array clarification system
based on the name with/without the square brackets, but short of
manually parsing the querystring/request headers, I have no
alternative to that.

Also my original problem came when I had to parse the results of a
form I did NOT originally create, not to mention forms from external
sources...

I don't hate PHP and I don't want to throw off people who like the []
system, just give me an alternative with a small overhead. :P


quick work around :) (could be improved)

 $pair ) {
$pair = explode( '=' , $pair , 2 );
if( !isset( $newGet[$pair[0]] ) ) {
$newGet[$pair[0]] = $pair[1];
} else {
if( !is_array($newGet[$pair[0]]) ) {
$newGet[$pair[0]] = array( $newGet[$pair[0]] );
}
$newGet[$pair[0]][] = $pair[1];
}
}
$_GET = $newGet;
}


print_r( $_GET );
fixGet();
print_r( $_GET );

?>

outputs:

Array
(
[toppings] => caramel
[order] => Order
)
Array
(
[toppings] => Array
(
[0] => nuts
[1] => fudge
[2] => caramel
)

[order] => Order
)


Yeah, and php://input should be able to handle $_POST, but custom 
functions ftl, the idea of having useless overhead for simple stuff like 
this makes me angry.


aye, at least it is possible to implement / work around quickly in 
userland - not sure if it makes me angry but things like this could be 
implemented easily internally I'm sure - wonder how a change like this 
would affect bc though, last thing you'd want is a tonne of sites 
breaking down because of a change like that - regardless that's not for 
my thought or debate.


btw as pointed out that chunk of code certainly isn't optimised or 
sanity checked for production use, and could easily (+should) be 
improved, but then that's what you get in a quick response on a mailing 
list - something to point you in the right direction and work with.


I do have to point out though that overhead with things like this aren't 
exactly problematic or noticeable - in-fact unless you have a massively 

Re: [PHP] Re: Parsing of forms

2009-05-20 Thread Daniele Grillenzoni

On 20/05/2009 2.45, Nathan Rixham wrote:

Daniele Grillenzoni wrote:

On 19/05/2009 18.09, Andrew Ballard wrote:

On Tue, May 19, 2009 at 10:11 AM, Ford, Mike
wrote:

On 19 May 2009 14:37, Daniele Grillenzoni advised:



My complaint is this: a I can have a select multiple with a
normal name,
which is allowed by every spec, but PHP requires me to use []
in order
to properly retrieve the values.


I really don't understand the problem with this -- in fact, I find it
quite useful to distinguish inputs which may have only 1 value from
those which may be multi-valued. And it all depends on what you mean by
a "normal" name, of course -- no current (X)HTML spec disallows [] as
part of a name attribute, so in that sense a name containing them could
be seen as perfectly normal...!! ;) ;)

Can you explain why this is such a hang-up for you, as I haven't seen
anything in what you've posted so far to convince me it's any kind of
problem?

Cheers!

Mike



I can't speak for the OP, but I've always thought it somewhat odd. An
HTML form should be able to work correctly without modification
regardless of the language that receives the input. As it is, it makes
the HTML for a form implementation specific. You might be able to use
ASP correctly process a form originally targeted toward PHP, but you
could not similarly take a form designed for ASP and process it with
PHP without modification.

It also impacts the use of client-side JavaScript. Consider a simple
page like this:

sundae.html
==



function countToppings() {
var totalToppings = 0;

var toppings = document.sundae.toppings;
// To work with PHP, the above line would have to be changed:
// var toppings = document.sundae.elements['toppings[]'];

if (toppings.length> 1) {
for (var i = 0; i< toppings.length; i++) {
if (toppings[i].checked) totalToppings++;
}
} else {
if (toppings.checked) totalToppings++
}

if (totalToppings == 0) {
confirm("Are you sure you don't want any toppings on your sundae?");
} else if (totalToppings> 3) {
alert("Wow! That's a lot of toppings!");
} else if (totalToppings == 1) {
alert("You only want one topping.");
} else {
alert("You have selected " + totalToppings + " toppings! Yummy!");
}
}






Toppings
 sprinkles
 nuts
 fudge
 caramel
 strawberries








The above form, if submitted, could build a perfectly valid query
string of
"?toppings=sprinkles&toppings=nuts&toppings=fudge&toppings=caramel&toppings=strawberries".


In the grand scheme of things, these are just subtleties that can
easily be handled. Since my first major experience with a web language
was PHP (after a very brief dabble in PERL) before I took a turn at
ASP/VBScript, I'm used to it and it isn't a "hang-up" for me. But
something about it never seemed quite "right" to me either. :-)

Andrew


Andrew captured perfectly what I meant.

"?toppings=sprinkles&toppings=nuts&toppings=fudge&toppings=caramel&toppings=strawberries"
is a valid querystring that php sort of fail at understanding.

I have nothing against supplying a string/array clarification system
based on the name with/without the square brackets, but short of
manually parsing the querystring/request headers, I have no
alternative to that.

Also my original problem came when I had to parse the results of a
form I did NOT originally create, not to mention forms from external
sources...

I don't hate PHP and I don't want to throw off people who like the []
system, just give me an alternative with a small overhead. :P


quick work around :) (could be improved)

 $pair ) {
$pair = explode( '=' , $pair , 2 );
if( !isset( $newGet[$pair[0]] ) ) {
$newGet[$pair[0]] = $pair[1];
} else {
if( !is_array($newGet[$pair[0]]) ) {
$newGet[$pair[0]] = array( $newGet[$pair[0]] );
}
$newGet[$pair[0]][] = $pair[1];
}
}
$_GET = $newGet;
}


print_r( $_GET );
fixGet();
print_r( $_GET );

?>

outputs:

Array
(
[toppings] => caramel
[order] => Order
)
Array
(
[toppings] => Array
(
[0] => nuts
[1] => fudge
[2] => caramel
)

[order] => Order
)


Yeah, and php://input should be able to handle $_POST, but custom 
functions ftl, the idea of having useless overhead for simple stuff like 
this makes me angry.


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



Re: [PHP] Re: Parsing of forms

2009-05-19 Thread Nathan Rixham

Daniele Grillenzoni wrote:

On 19/05/2009 18.09, Andrew Ballard wrote:
On Tue, May 19, 2009 at 10:11 AM, Ford, Mike  
wrote:

On 19 May 2009 14:37, Daniele Grillenzoni advised:



My complaint is this: a I can have a select multiple with a
normal name,
which is allowed by every spec, but PHP requires me to use []
in order
to properly retrieve the values.


I really don't understand the problem with this -- in fact, I find it
quite useful to distinguish inputs which may have only 1 value from
those which may be multi-valued. And it all depends on what you mean by
a "normal" name, of course -- no current (X)HTML spec disallows [] as
part of a name attribute, so in that sense a name containing them could
be seen as perfectly normal...!! ;) ;)

Can you explain why this is such a hang-up for you, as I haven't seen
anything in what you've posted so far to convince me it's any kind of
problem?

Cheers!

Mike



I can't speak for the OP, but I've always thought it somewhat odd. An
HTML form should be able to work correctly without modification
regardless of the language that receives the input. As it is, it makes
the HTML for a form implementation specific. You might be able to use
ASP correctly process a form originally targeted toward PHP, but you
could not similarly take a form designed for ASP and process it with
PHP without modification.

It also impacts the use of client-side JavaScript. Consider a simple
page like this:

sundae.html
==



function countToppings() {
var totalToppings = 0;

var toppings = document.sundae.toppings;
// To work with PHP, the above line would have to be changed: // var toppings = document.sundae.elements['toppings[]'];

if (toppings.length>  1) {
for (var i = 0; i<  toppings.length; i++) {
if (toppings[i].checked) totalToppings++;
}
} else {
if (toppings.checked) totalToppings++
}

if (totalToppings == 0) {
confirm("Are you sure you don't want any toppings on your sundae?");
} else if (totalToppings>  3) {
alert("Wow! That's a lot of toppings!");
} else if (totalToppings == 1) {
alert("You only want one topping.");
} else {
alert("You have selected " + totalToppings + " toppings! Yummy!");
}
}






Toppings
  sprinkles
  nuts
  fudge
  caramel
  strawberries








The above form, if submitted, could build a perfectly valid query
string of 
"?toppings=sprinkles&toppings=nuts&toppings=fudge&toppings=caramel&toppings=strawberries". 



In the grand scheme of things, these are just subtleties that can
easily be handled. Since my first major experience with a web language
was PHP (after a very brief dabble in PERL) before I took a turn at
ASP/VBScript, I'm used to it and it isn't a "hang-up" for me. But
something about it never seemed quite "right" to me either. :-)

Andrew


Andrew captured perfectly what I meant.

"?toppings=sprinkles&toppings=nuts&toppings=fudge&toppings=caramel&toppings=strawberries" 
is a valid querystring that php sort of fail at understanding.


I have nothing against supplying a string/array clarification system 
based on the name with/without the square brackets, but short of 
manually parsing the querystring/request headers, I have no alternative 
to that.


Also my original problem came when I had to parse the results of a form 
I did NOT originally create, not to mention forms from external sources...


I don't hate PHP and I don't want to throw off people who like the [] 
system, just give me an alternative with a small overhead. :P


quick work around :) (could be improved)

 $pair ) {
$pair = explode( '=' , $pair , 2 );
if( !isset( $newGet[$pair[0]] ) ) {
  $newGet[$pair[0]] = $pair[1];
} else {
  if( !is_array($newGet[$pair[0]]) ) {
$newGet[$pair[0]] = array( $newGet[$pair[0]] );
  }
  $newGet[$pair[0]][] = $pair[1];
}
  }
  $_GET = $newGet;
}


print_r( $_GET );
fixGet();
print_r( $_GET );

?>

outputs:

Array
(
[toppings] => caramel
[order] => Order
)
Array
(
[toppings] => Array
(
[0] => nuts
[1] => fudge
[2] => caramel
)

[order] => Order
)

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



Re: [PHP] Re: Parsing of forms

2009-05-19 Thread Daniele Grillenzoni

On 19/05/2009 18.09, Andrew Ballard wrote:

On Tue, May 19, 2009 at 10:11 AM, Ford, Mike  wrote:

On 19 May 2009 14:37, Daniele Grillenzoni advised:



My complaint is this: a I can have a select multiple with a
normal name,
which is allowed by every spec, but PHP requires me to use []
in order
to properly retrieve the values.


I really don't understand the problem with this -- in fact, I find it
quite useful to distinguish inputs which may have only 1 value from
those which may be multi-valued. And it all depends on what you mean by
a "normal" name, of course -- no current (X)HTML spec disallows [] as
part of a name attribute, so in that sense a name containing them could
be seen as perfectly normal...!! ;) ;)

Can you explain why this is such a hang-up for you, as I haven't seen
anything in what you've posted so far to convince me it's any kind of
problem?

Cheers!

Mike



I can't speak for the OP, but I've always thought it somewhat odd. An
HTML form should be able to work correctly without modification
regardless of the language that receives the input. As it is, it makes
the HTML for a form implementation specific. You might be able to use
ASP correctly process a form originally targeted toward PHP, but you
could not similarly take a form designed for ASP and process it with
PHP without modification.

It also impacts the use of client-side JavaScript. Consider a simple
page like this:

sundae.html
==



function countToppings() {
var totalToppings = 0;

var toppings = document.sundae.toppings;
 // To work with PHP, the above line would have to be changed:
 // var toppings = document.sundae.elements['toppings[]'];

if (toppings.length>  1) {
for (var i = 0; i<  toppings.length; i++) {
if (toppings[i].checked) totalToppings++;
}
} else {
if (toppings.checked) totalToppings++
}

if (totalToppings == 0) {
confirm("Are you sure you don't want any toppings on your 
sundae?");
} else if (totalToppings>  3) {
alert("Wow! That's a lot of toppings!");
} else if (totalToppings == 1) {
alert("You only want one topping.");
} else {
alert("You have selected " + totalToppings + " toppings! 
Yummy!");
}
}






Toppings
  sprinkles
  nuts
  fudge
  caramel
  strawberries








The above form, if submitted, could build a perfectly valid query
string of 
"?toppings=sprinkles&toppings=nuts&toppings=fudge&toppings=caramel&toppings=strawberries".

In the grand scheme of things, these are just subtleties that can
easily be handled. Since my first major experience with a web language
was PHP (after a very brief dabble in PERL) before I took a turn at
ASP/VBScript, I'm used to it and it isn't a "hang-up" for me. But
something about it never seemed quite "right" to me either. :-)

Andrew


Andrew captured perfectly what I meant.

"?toppings=sprinkles&toppings=nuts&toppings=fudge&toppings=caramel&toppings=strawberries" 
is a valid querystring that php sort of fail at understanding.


I have nothing against supplying a string/array clarification system 
based on the name with/without the square brackets, but short of 
manually parsing the querystring/request headers, I have no alternative 
to that.


Also my original problem came when I had to parse the results of a form 
I did NOT originally create, not to mention forms from external sources...


I don't hate PHP and I don't want to throw off people who like the [] 
system, just give me an alternative with a small overhead. :P


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



Re: [PHP] Re: Parsing of forms

2009-05-19 Thread Andrew Ballard
On Tue, May 19, 2009 at 10:11 AM, Ford, Mike  wrote:
> On 19 May 2009 14:37, Daniele Grillenzoni advised:
>
>>
>> My complaint is this: a I can have a select multiple with a
>> normal name,
>> which is allowed by every spec, but PHP requires me to use []
>> in order
>> to properly retrieve the values.
>
> I really don't understand the problem with this -- in fact, I find it
> quite useful to distinguish inputs which may have only 1 value from
> those which may be multi-valued. And it all depends on what you mean by
> a "normal" name, of course -- no current (X)HTML spec disallows [] as
> part of a name attribute, so in that sense a name containing them could
> be seen as perfectly normal...!! ;) ;)
>
> Can you explain why this is such a hang-up for you, as I haven't seen
> anything in what you've posted so far to convince me it's any kind of
> problem?
>
> Cheers!
>
> Mike
>

I can't speak for the OP, but I've always thought it somewhat odd. An
HTML form should be able to work correctly without modification
regardless of the language that receives the input. As it is, it makes
the HTML for a form implementation specific. You might be able to use
ASP correctly process a form originally targeted toward PHP, but you
could not similarly take a form designed for ASP and process it with
PHP without modification.

It also impacts the use of client-side JavaScript. Consider a simple
page like this:

sundae.html
==



function countToppings() {
var totalToppings = 0;

var toppings = document.sundae.toppings;
// To work with PHP, the above line would have to be changed:
// var toppings = document.sundae.elements['toppings[]'];

if (toppings.length > 1) {
for (var i = 0; i < toppings.length; i++) {
if (toppings[i].checked) totalToppings++;
}
} else {
if (toppings.checked) totalToppings++
}

if (totalToppings == 0) {
confirm("Are you sure you don't want any toppings on 
your sundae?");
} else if (totalToppings > 3) {
alert("Wow! That's a lot of toppings!");
} else if (totalToppings == 1) {
alert("You only want one topping.");
} else {
alert("You have selected " + totalToppings + " 
toppings! Yummy!");
}
}






Toppings
 sprinkles
 nuts
 fudge
 caramel
 strawberries








The above form, if submitted, could build a perfectly valid query
string of 
"?toppings=sprinkles&toppings=nuts&toppings=fudge&toppings=caramel&toppings=strawberries".

In the grand scheme of things, these are just subtleties that can
easily be handled. Since my first major experience with a web language
was PHP (after a very brief dabble in PERL) before I took a turn at
ASP/VBScript, I'm used to it and it isn't a "hang-up" for me. But
something about it never seemed quite "right" to me either. :-)

Andrew

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



RE: [PHP] Re: Parsing of forms

2009-05-19 Thread Ford, Mike
On 19 May 2009 14:37, Daniele Grillenzoni advised:

> 
> My complaint is this: a I can have a select multiple with a
> normal name,
> which is allowed by every spec, but PHP requires me to use []
> in order
> to properly retrieve the values.

I really don't understand the problem with this -- in fact, I find it
quite useful to distinguish inputs which may have only 1 value from
those which may be multi-valued. And it all depends on what you mean by
a "normal" name, of course -- no current (X)HTML spec disallows [] as
part of a name attribute, so in that sense a name containing them could
be seen as perfectly normal...!! ;) ;)

Can you explain why this is such a hang-up for you, as I haven't seen
anything in what you've posted so far to convince me it's any kind of
problem?

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: m.f...@leedsmet.ac.uk
Tel: +44 113 812 4730


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



[PHP] Re: Parsing of forms

2009-05-19 Thread Daniele Grillenzoni

On 18/05/2009 10.42, Peter Ford wrote:

Daniele Grillenzoni wrote:

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


Isn't it ironic that a post about multiple form inputs is posted four times?
That's not a good way to make friends here, Daniele...

I really don't understand your complaint - in general if your form has multiple
inputs with the same name, then you either meant to do that, (like a multiple
select, in which case there's not really a big deal to add the []),
or it's wrong and wouldn't work as expected anyway.

You could append [] to every input - that would be lovely, but it would hide the
possibility that you mistakenly gave two inputs the same name.

It's true that every so often I can't work out why something is not posting an
array to PHP when I expected it to, and a look back to the form to find I'd
missed a [] on the name is the answer.

As I like to say in other areas of life (especially to my children), "stop
whining and get on with it!" ( sorry :) )

I'm sorry, it was due to my antispam block, which in turn blocked the 
mailing list antispam check. Quite ironic indeed. Also I thought I 
canceled the other 3, apparently it's something that is only apparent.


My complaint is this: a I can have a select multiple with a normal name, 
which is allowed by every spec, but PHP requires me to use [] in order 
to properly retrieve the values.


I guess I would settle for a function or an alternative array to $_GET 
and $_POST that worked properly.


Creating a function to fix those things is actually not that hard, but 
calling it everytime you need to use those arrays creates a lot of 
overhead. So maybe a core, or a PECL extension is/would be the answer.


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



[PHP] Re: Parsing of forms

2009-05-18 Thread Peter Ford
Daniele Grillenzoni wrote:
> 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  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?

Isn't it ironic that a post about multiple form inputs is posted four times?
That's not a good way to make friends here, Daniele...

I really don't understand your complaint - in general if your form has multiple
inputs with the same name, then you either meant to do that, (like a multiple
select, in which case there's not really a big deal to add the []),
or it's wrong and wouldn't work as expected anyway.

You could append [] to every input - that would be lovely, but it would hide the
possibility that you mistakenly gave two inputs the same name.

It's true that every so often I can't work out why something is not posting an
array to PHP when I expected it to, and a look back to the form to find I'd
missed a [] on the name is the answer.

As I like to say in other areas of life (especially to my children), "stop
whining and get on with it!" ( sorry :) )

-- 
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: Parsing XML

2008-11-28 Thread Ashley Sheridan
On Fri, 2008-11-28 at 13:48 +, Nathan Rixham wrote:
> 2008/11/27 Ashley Sheridan <[EMAIL PROTECTED]>
> 
> On Thu, 2008-11-27 at 22:13 +, Ashley Sheridan wrote:
> > On Thu, 2008-11-27 at 20:56 +, Nathan Rixham wrote:
> > > Ashley Sheridan wrote:
> > > > 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
> > > >
> > >
> > > standard response which has helped a few recently :p
> > >
> > > "you could give this a go if you like (one i made
> earlier):
> > > http://programphp.com/xmlparser.phps - class at the top,
> usage at the
> > > bottom."
> > >
> > I've started using DOMDocument for this (I bypassed your
> code for the
> > moment as it uses regular expressions, which were a speed
> bottleneck
> > with my approach) but I can't find any proper documentation
> on it
> > online. My efforts so far have resulted in a lot of errors
> which are
> > nigh on impossible to debug. I've used the dom class in
> javascript
> > without problems now, and it seems to look similar, but it's
> all going
> > wrong!
> >
> >
> > Ash
> > www.ashleysheridan.co.uk
> >
> >
> 
> OK, given up on DOMDocument, and tried your code Nathan, works
> beautifully! Turns out the slow speeds I was experiencing
> before using
> the regexes was down to the remote server serving out the xml
> document.
> Its the armory server on wow-europe, so not too worried about
> that!
> 
> 
> 
> Ash
> www.ashleysheridan.co.uk
> 
> 
> glad to be of service; if you can use DOMDocument I've got a whole
> fleet of xml parsers written up using it, and auto xml to object
> convertors etc etc - or there's a commercial version available I made
> some time ago aswell http://rssphp.net/ v3
> but just ask me got ones better since :)

Thanks, if I run into any problems with this, I might look at that.
You've been a great help!


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Re: Parsing XML

2008-11-28 Thread Nathan Rixham
2008/11/27 Ashley Sheridan <[EMAIL PROTECTED]>

> On Thu, 2008-11-27 at 22:13 +, Ashley Sheridan wrote:
> > On Thu, 2008-11-27 at 20:56 +, Nathan Rixham wrote:
> > > Ashley Sheridan wrote:
> > > > 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
> > > >
> > >
> > > standard response which has helped a few recently :p
> > >
> > > "you could give this a go if you like (one i made earlier):
> > > http://programphp.com/xmlparser.phps - class at the top, usage at the
> > > bottom."
> > >
> > I've started using DOMDocument for this (I bypassed your code for the
> > moment as it uses regular expressions, which were a speed bottleneck
> > with my approach) but I can't find any proper documentation on it
> > online. My efforts so far have resulted in a lot of errors which are
> > nigh on impossible to debug. I've used the dom class in javascript
> > without problems now, and it seems to look similar, but it's all going
> > wrong!
> >
> >
> > Ash
> > www.ashleysheridan.co.uk
> >
> >
> OK, given up on DOMDocument, and tried your code Nathan, works
> beautifully! Turns out the slow speeds I was experiencing before using
> the regexes was down to the remote server serving out the xml document.
> Its the armory server on wow-europe, so not too worried about that!
>
>
> Ash
> www.ashleysheridan.co.uk
>
> glad to be of service; if you can use DOMDocument I've got a whole fleet of
xml parsers written up using it, and auto xml to object convertors etc etc -
or there's a commercial version available I made some time ago aswell
http://rssphp.net/ v3
but just ask me got ones better since :)


Re: [PHP] Re: Parsing XML

2008-11-27 Thread Ashley Sheridan
On Fri, 2008-11-28 at 01:04 +0100, Maciek Sokolewicz wrote:
> Ashley Sheridan wrote:
> > On Thu, 2008-11-27 at 22:13 +, Ashley Sheridan wrote:
> >> On Thu, 2008-11-27 at 20:56 +, Nathan Rixham wrote:
> >>> Ashley Sheridan wrote:
>  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
> 
> >>> standard response which has helped a few recently :p
> >>>
> >>> "you could give this a go if you like (one i made earlier): 
> >>> http://programphp.com/xmlparser.phps - class at the top, usage at the 
> >>> bottom."
> >>>
> >> I've started using DOMDocument for this (I bypassed your code for the
> >> moment as it uses regular expressions, which were a speed bottleneck
> >> with my approach) but I can't find any proper documentation on it
> >> online. My efforts so far have resulted in a lot of errors which are
> >> nigh on impossible to debug. I've used the dom class in javascript
> >> without problems now, and it seems to look similar, but it's all going
> >> wrong!
> >>
> >>
> >> Ash
> >> www.ashleysheridan.co.uk
> >>
> >>
> > OK, given up on DOMDocument, and tried your code Nathan, works
> > beautifully! Turns out the slow speeds I was experiencing before using
> > the regexes was down to the remote server serving out the xml document.
> > Its the armory server on wow-europe, so not too worried about that!
> > 
> > 
> > Ash
> > www.ashleysheridan.co.uk
> > 
> 
> the armory at wow-europe? That thing is horribly overloaded 
> [permanently], get used to it. I've had a few scripts have trouble with 
> that place aswell, considering connections timed out regularly.
> 
> - Tul
> 
Yeah, the very same.

I'm trying to avoid as much communication with it as possible, by only
updating content once an hour, and then only if that content is
requested, so if the site doesn't get used for a week, no updates are
made. And then, all the data is stored in a database at my end, so I can
query that easily.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Re: Parsing XML

2008-11-27 Thread Maciek Sokolewicz

Ashley Sheridan wrote:

On Thu, 2008-11-27 at 22:13 +, Ashley Sheridan wrote:

On Thu, 2008-11-27 at 20:56 +, Nathan Rixham wrote:

Ashley Sheridan wrote:

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


standard response which has helped a few recently :p

"you could give this a go if you like (one i made earlier): 
http://programphp.com/xmlparser.phps - class at the top, usage at the 
bottom."



I've started using DOMDocument for this (I bypassed your code for the
moment as it uses regular expressions, which were a speed bottleneck
with my approach) but I can't find any proper documentation on it
online. My efforts so far have resulted in a lot of errors which are
nigh on impossible to debug. I've used the dom class in javascript
without problems now, and it seems to look similar, but it's all going
wrong!


Ash
www.ashleysheridan.co.uk



OK, given up on DOMDocument, and tried your code Nathan, works
beautifully! Turns out the slow speeds I was experiencing before using
the regexes was down to the remote server serving out the xml document.
Its the armory server on wow-europe, so not too worried about that!


Ash
www.ashleysheridan.co.uk



the armory at wow-europe? That thing is horribly overloaded 
[permanently], get used to it. I've had a few scripts have trouble with 
that place aswell, considering connections timed out regularly.


- Tul

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



Re: [PHP] Re: Parsing XML

2008-11-27 Thread Ashley Sheridan
On Thu, 2008-11-27 at 22:13 +, Ashley Sheridan wrote:
> On Thu, 2008-11-27 at 20:56 +, Nathan Rixham wrote:
> > Ashley Sheridan wrote:
> > > 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
> > > 
> > 
> > standard response which has helped a few recently :p
> > 
> > "you could give this a go if you like (one i made earlier): 
> > http://programphp.com/xmlparser.phps - class at the top, usage at the 
> > bottom."
> > 
> I've started using DOMDocument for this (I bypassed your code for the
> moment as it uses regular expressions, which were a speed bottleneck
> with my approach) but I can't find any proper documentation on it
> online. My efforts so far have resulted in a lot of errors which are
> nigh on impossible to debug. I've used the dom class in javascript
> without problems now, and it seems to look similar, but it's all going
> wrong!
> 
> 
> Ash
> www.ashleysheridan.co.uk
> 
> 
OK, given up on DOMDocument, and tried your code Nathan, works
beautifully! Turns out the slow speeds I was experiencing before using
the regexes was down to the remote server serving out the xml document.
Its the armory server on wow-europe, so not too worried about that!


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Re: Parsing XML

2008-11-27 Thread Ashley Sheridan
On Thu, 2008-11-27 at 20:56 +, Nathan Rixham wrote:
> Ashley Sheridan wrote:
> > 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
> > 
> 
> standard response which has helped a few recently :p
> 
> "you could give this a go if you like (one i made earlier): 
> http://programphp.com/xmlparser.phps - class at the top, usage at the 
> bottom."
> 
I've started using DOMDocument for this (I bypassed your code for the
moment as it uses regular expressions, which were a speed bottleneck
with my approach) but I can't find any proper documentation on it
online. My efforts so far have resulted in a lot of errors which are
nigh on impossible to debug. I've used the dom class in javascript
without problems now, and it seems to look similar, but it's all going
wrong!


Ash
www.ashleysheridan.co.uk


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



[PHP] Re: Parsing XML

2008-11-27 Thread Nathan Rixham

Ashley Sheridan wrote:

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



standard response which has helped a few recently :p

"you could give this a go if you like (one i made earlier): 
http://programphp.com/xmlparser.phps - class at the top, usage at the 
bottom."


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



[PHP] Re: Parsing XML

2008-11-27 Thread Nathan Rixham

Ashley Sheridan wrote:

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



standard response which has helped a few recently :p

"you could give this a go if you like (one i made earlier): 
http://programphp.com/xmlparser.phps - class at the top, usage at the 
bottom."


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



[PHP] Re: Parsing mail file

2007-02-01 Thread tom

Easy!!
Pierre Pintaric :

Hello there,

I'm sure this question was ask 1,000 times, but I didn't find any 
archive about this, that's why I need help...


Here is my problem:
I receive mail file from my MTA (ie QMail), that works fine. Now, I 
would to find a class or a function that parse the mail and gives 
headers informations, body of the mail (even if it is a multi-part mail) 
and file attachments.

I found nothing in PEAR library, nothing on the web, ...

I don't what want to rebuild the wheel if somebody works on it and made 
a good job...
If somebody uses a great function and want to share, I will please 
him... :-)


Thanks for your help.

Pierre


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



[PHP] Re: Parsing AJAX post data -- The Way

2007-01-25 Thread Colin Guthrie
Stut wrote:
> M5 wrote:
>> Just wondering what smart people do for parsing data sent by the
>> Javascript XMLHTTP object--e.g., http.send("post",url,true)...
>>
>> In a normal form submit, the $_POST global nicely allocates form
>> elements as array elements automatically. But with the AJAX way, the
>> data get stuffed inside $HTTP_RAW_POST_DATA as a string, thereby
>> making extraction more tedious.
> 
> What format is the data you are posting in? If it's in the usual format,
> PHP should parse it for you. An AJAX (hate that acronym) post request is
> no different to a normal post, unless you are not posting in the form
> format (var1=val2&var2=val2).

Yes, just to elaborate, consider the following (simple AJAX post (using
prototype.js as it's great!).


function SendRemote(action)
{
  new Ajax.Request('backend.php', { parameters: 'submit='+action });
}

This sends a simple form POSTED to the server with one form element
(named "submit") which will be available to the server as $_POST['submit'].

If you want to add more, just use the & as Stut suggests, e.g.:

function SendRemote(action)
{
  new Ajax.Request('backend.php', { parameters:
'submit='+action+'&var2=xxx' });
}

etc.

HTH

Col.

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



[PHP] Re: Parsing an XML return from a POST

2007-01-08 Thread Fahad Pervaiz

===ORIGINAL===
Hi List

I am working owards completing a rather urgent project for one of our
clients.
There is a requirement to send a request to a server and I now have that
working
using cURL, thanks to help from this list. I now have the responses coming
back
as an XML response. What I need to do is to parse the XML response and break
it
up into either an array or variables so I can pass the returned responses
back
to a calling process.

I have spent most of last night and today looking at XML parsing and now am
totally confused. Some testing I have done suggests that SimpleXML is not
the
way to go however I am open to suggestions if it might be an answer. I would
appreciate any help or advice on how to parse this XML response and break it
up
into either an array or individual variables.

I have included a sample response from the server below. A few points to be
aware of,

1) In the fares section there could be any number of fares however each fare
will have a fareID and then the fareBases child.
2) In the tarifs section there could be any number of tarifs however each
tarif
will have a tarifId and then 1 or more fareXrefs.
3) In the vcrSummary section there could be 1 or more vcr entries
4) The response comes back as one long string and I have formatted this to
make
it a little easier to read.





  
  
  VLOX2
  VLOX2
  VLOX2
  
  
  
  
  MLOW2
  MLOW2
  MLOW2
  
  


  
  
  11429927
  
  
  
  
  11429926
  
  


  201.52


  AA
  PR




I would certainly appreciate any help I can get. Thanks in advance.
===END ORIGINAL===

You can easily parse XML using "XML Parser Functions" or "DOM Functions"
available in PHP

Lots of classes have been written to parse xml using the above
libraries.Youcan easily search them on google.

--
Regards
Fahad Pervaiz
www.ecommerce-xperts.com
(Shopping Cart, Web Design, SEO, VoIP)


[PHP] Re: parsing out quoted text

2006-06-11 Thread Stian Berger

On Fri, 09 Jun 2006 14:53:09 +0200, sam <[EMAIL PROTECTED]> wrote:



$str='bass "electric organ" bagpipes';

$parser($str);

$query="SELECT * FROM table WHERE tb_instr = "bass"
> AND tb_instr = "electric organ" //< AND tb_instr = "bagpipes";


Anybody know where I can just copy code that will do the above?

thanks


I once for just the fun of it, made a regular expression to solve
this kind of problem. I haven't tried it in production enviroment,
but only on some basic examples. It should support both single and
double quotes.

$str = 'bass "electric organ" bagpipes';
preg_match_all("/(?<=('|\"))[^\\1]+(?=\\1)|[^ \"']+/",$str,$match);
/*
$match[0] Array
(
[0] => bass
[1] => electric organ
[2] => bagpipes
)
*/
foreach($match[0] as $key => $value) {
$match[0][$key] = 'tb_instr = "'.mysql_escape_string($value).'"';
}
$sql = "SELECT * FROM table WHERE ".implode(' AND ',$match[0]);
print($sql);

//SELECT * FROM table WHERE tb_instr = "bass" AND
//tb_instr = "electric organ" AND tb_instr = "bagpipes"

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



[PHP] Re: parsing/replacing for special MS Word characters

2006-05-24 Thread Al

I Dan McCullough wrote:

I have a friend who I wrote some very simple publishing software,
basically he takes his writtings and puts them online.  Well his
writtings are in Word and so he has alot of special characters that he
inputs, some unknowingly, into the database.  Are there any classes or
samples of what others have done to strip/replace/find these special
characters, I have asked him to be careful, but he will do it once or
twice and then forget and lapse, and I get a call saying can you help
me get these out.

Any idea


I use in the header 

Then for the uploaded text:
$translate_array= array(//converts MS chars to html; this will 
catch most of them
chr(133)=> '...',
chr(145)=> '\'',
chr(146)=> '\'',
chr(147)=> '"',
chr(148)=> '"',
chr(150)=> '-',
chr(151)=> '-',
);

$str= strtr($str, $translate_array);

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



Re: [PHP] Re: Parsing variables within string variables

2006-04-08 Thread David Clough

Dear Paul,

this is exactly the solution I needed, and works as described! Many  
thanks for thinking through this with me.


Yours,

David.

On 8 Apr 2006, at 00:05, Paul Novitski wrote:


At 02:41 PM 4/7/2006, David Clough wrote:

I have to parse the string 'Hello $foo' as it comes from the
database: I don't get to construct it.

I did hold out more hope for the eval function, but it seems to me  
that

this is for PHP code in a database, not to evaluate variables.



David, please try the eval() route: it will do what you want.  You  
say, "this is for PHP code in a database, not to evaluate  
variables," but evaluating variables is absolutely part of PHP code  
processing!  Eval() will operate on "$x = 4;" just as easily as on  
"Hello $foo."


You should not use eval() frivolously because it presents a  
potential vulnerability in your code.  You may wish to ensure that  
the database text it operates on is first cleansed of any other PHP  
syntax -- similarly to the way we should all ensure that any  
incoming data is clean before we process it and incorporate it into  
our scripts.


Here's an example of variaible evaluation:
___

$bar = "cat";
$foo = "Hello \$bar.";

echo $foo;
RESULT: Hello $bar.

By escaping the $, I have made it a literal character in the text,  
the same as if I'd read "Hello $bar" from a database.

___

eval("echo \"$foo\";");
RESULT: Hello cat.

This is equivalent to scripting:
echo "$foo";
I'm using eval() to execute the echo command and interpret the PHP  
variable $foo.

___

eval("\$dog = \$bar;");
echo "dog = " . $dog;

RESULT: dog = cat

Here I'm using eval() to set one PHP variable equal to another.
___

You can't simply write:
eval("\$bar;");
or
$x = eval($foo);

because everything inside the eval() parentheses needs to be a  
complete PHP statement.  The eval() function itself doesn't return  
the value of an evaluated expression.  To capture the value of an  
expression, you must evaluate a complete statement that sets a  
variable equal to the expression as above.

___

Clear as mud?

Regards,
Paul


--
Dr. David Clough
Tutor in Ethics and Systematic Theology; Director of Studies
Cranmer Hall, St. John's College, Durham DH1 3RJ, U. K.
Tel. +44 (0)191 334 3858 Fax. +44 (0)191 334 3501
[EMAIL PROTECTED]
--
E-MAIL WARNING;
The information in this e-mail is confidential and may be subject to  
legal professional privilege.  It is intended solely for the  
attention and use of the named addressee(s). If you are not the  
intended recipient, please notify the sender immediately.  Unless you  
are the intended recipient or his/her representative you are not  
authorised to, and must not, read, copy, distribute, use or retain  
this message or any part of it.


At present the integrity of e-mail across the Internet cannot be  
guaranteed and messages and documents sent via this medium are  
potentially at risk. You should perform your own virus checks before  
opening any documents sent with this message. All liability is  
excluded to the extent permitted by law for any claims arising from  
the use of this medium by St John's College Durham.





Re: [PHP] Re: Parsing variables within string variables

2006-04-07 Thread Paul Novitski

At 02:41 PM 4/7/2006, David Clough wrote:

I have to parse the string 'Hello $foo' as it comes from the
database: I don't get to construct it.

I did hold out more hope for the eval function, but it seems to me that
this is for PHP code in a database, not to evaluate variables.



David, please try the eval() route: it will do what you want.  You 
say, "this is for PHP code in a database, not to evaluate variables," 
but evaluating variables is absolutely part of PHP code 
processing!  Eval() will operate on "$x = 4;" just as easily as on 
"Hello $foo."


You should not use eval() frivolously because it presents a potential 
vulnerability in your code.  You may wish to ensure that the database 
text it operates on is first cleansed of any other PHP syntax -- 
similarly to the way we should all ensure that any incoming data is 
clean before we process it and incorporate it into our scripts.


Here's an example of variaible evaluation:
___

$bar = "cat";
$foo = "Hello \$bar.";

echo $foo;
RESULT: Hello $bar.

By escaping the $, I have made it a literal character in the text, 
the same as if I'd read "Hello $bar" from a database.

___

eval("echo \"$foo\";");
RESULT: Hello cat.

This is equivalent to scripting:
echo "$foo";
I'm using eval() to execute the echo command and interpret the PHP 
variable $foo.

___

eval("\$dog = \$bar;");
echo "dog = " . $dog;

RESULT: dog = cat

Here I'm using eval() to set one PHP variable equal to another.
___

You can't simply write:
eval("\$bar;");
or
$x = eval($foo);

because everything inside the eval() parentheses needs to be a 
complete PHP statement.  The eval() function itself doesn't return 
the value of an evaluated expression.  To capture the value of an 
expression, you must evaluate a complete statement that sets a 
variable equal to the expression as above.

___

Clear as mud?

Regards,
Paul 


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



[PHP] Re: Parsing variables within string variables

2006-04-07 Thread David Clough
Thanks for all these responses, but unless I'm missing something none of 
them work for what I need. Quotes are irrelevant: with the string "Hello 
$foo" in $bar

   echo "$bar"
   echo $bar

both produce
   
   Hello $foo

and

   echo '$bar'

produces
   
   $bar

I can't use any of the answers like

   'Hello'.$foo

because I have to parse the string 'Hello $foo' as it comes from the 
database: I don't get to construct it.

I did hold out more hope for the eval function, but it seems to me that 
this is for PHP code in a database, not to evaluate variables.

If anyone else can provide the silver bullet, I will be very grateful.

   David.

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (David Clough) wrote:

> I've been bashing my head against the wall on this, and would be glad of 
> help to stop. 
> 
> I have a variable containing a string that contains the names of 
> variables, and want to output the variable with the variables it 
> contains evaluated. E.g. 
> 
>$foo contains 'cat'
>$bar contains 'Hello $foo'
> 
> and I want to output $bar as 
> 
>Hello cat
> 
> The problem is that if I use
> 
>echo $bar
> 
> I just get
> 
>Hello $foo
> 
> Note that $bar is loaded from a database query, so I can't control its 
> contents: I just have to parse it.
> 
> Any help appreciated.
> 
> David.

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



[PHP] Re: Parsing PHP variables in XML document

2006-02-27 Thread Ivan Nedialkov
I comed up with this

$name,"attrs"=>$attrs); 
   array_push($stack,$tag);
}

// end_element_handler ( resource parser, string name )
function endElement($parser, $name)
{
   global $stack; 
   $stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
   array_pop($stack);
}

// handler ( resource parser, string data )
function characterData($parser, $data)
{
   global $stack,$i;
   
   eval("\$data = \"$data\";"); 

   if(trim($data))
   {  
$stack[count($stack)-1]['data']=$data;   
   }
}

// handler ( resource parser, string target, string data )
function PIHandler($parser, $target, $data)
{
   if ((strtolower($target)) == "php") {
global $parser_file;
  eval($data);
   }
}

function defaultHandler($parser, $data)
{

}

function externalEntityRefHandler($parser, $openEntityNames, $base,
$systemId,
 $publicId) {
   if ($systemId) {
   if (!list($parser, $fp) = new_xml_parser($systemId)) {
   printf("Could not open entity %s at %s\n", $openEntityNames,
   $systemId);
   return false;
   }
   while ($data = fread($fp, 4096)) {
   if (!xml_parse($parser, $data, feof($fp))) {
   printf("XML error: %s at line %d while parsing entity %s
\n",
   xml_error_string(xml_get_error_code($parser)),
   xml_get_current_line_number($parser),
$openEntityNames);
   xml_parser_free($parser);
   return false;
   }
   }
   xml_parser_free($parser);
   return true;
   }
   return false;
}



function new_xml_parser($file)
{
   global $parser_file;
$xml_parser = xml_parser_create();
   
   xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
   
   xml_set_processing_instruction_handler($xml_parser, "PIHandler");
   
   xml_set_element_handler($xml_parser, "startElement", "endElement");
   
   xml_set_character_data_handler($xml_parser, "characterData"); 
   
   xml_set_default_handler($xml_parser, "defaultHandler");
   
   xml_set_external_entity_ref_handler($xml_parser,
"externalEntityRefHandler");
  
   if (!($fp = @fopen($file, "r"))) {
   return false;
   }
   if (!is_array($parser_file)) {
   settype($parser_file, "array");
   }
   $parser_file[$xml_parser] = $file;
   return array($xml_parser, $fp);
}


if (!(list($xml_parser, $fp) = new_xml_parser($file))) {
   die("could not open XML input");
}

//ERROR
while ($data = fread($fp, 4096)) {
   if (!xml_parse($xml_parser, $data, feof($fp))) {
   die(sprintf("XML error: %s at line %d\n",
   xml_error_string(xml_get_error_code($xml_parser)),
   xml_get_current_line_number($xml_parser)));
   }
}
//END
xml_parser_free($xml_parser);

print("\n");
print_r($stack);
print("\n");


?>

it evaluates php code. But when I use 

eval("\$data = \"$data\";");

the strings in the $data e.g. ('sth $foo other $foo1')do not appear. I
think the problem is that it thinks they are undefined. 

Here is the xml file



]>


   


hi 

foo $foo3 foo



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



[PHP] Re: Parsing PHP variables in XML document

2006-02-27 Thread Ivan Nedialkov


So I have found this code in http://bg.php.net/manual/en/ref.xmlrpc.php
and it evaluates PHP but when I try to use the PIHandler separately. It
doesnt work. So I ask if someone could help me to make parser1 return an
array just like parser2.

PARSER1

$name";
   if (count($attribs)) {
   foreach ($attribs as $k => $v) {
   echo " $k=\"$v\"";
   }
   }
   echo ">";
}

function endElement($parser, $name)
{
   echo "";
}

function characterData($parser, $data)
{
   echo "$data";
}

function PIHandler($parser, $target, $data)
{
   switch (strtolower($target)) {
   case "php":
   global $parser_file;
   // If the parsed document is "trusted", we say it is safe
   // to execute PHP code inside it.  If not, display the code
   // instead.
   if (trustedFile($parser_file[$parser])) {
   eval($data);
   } else {
   printf("Untrusted PHP code: %s",
   htmlspecialchars($data));
   }
   break;
   }
}

function defaultHandler($parser, $data)
{
   if (substr($data, 0, 1) == "&" && substr($data, -1, 1) == ";") {
   printf('%s',
   htmlspecialchars($data));
   } else {
   printf('%s',
   htmlspecialchars($data));
   }
}

function externalEntityRefHandler($parser, $openEntityNames, $base,
$systemId,
 $publicId) {
   if ($systemId) {
   if (!list($parser, $fp) = new_xml_parser($systemId)) {
   printf("Could not open entity %s at %s\n", $openEntityNames,
   $systemId);
   return false;
   }
   while ($data = fread($fp, 4096)) {
   if (!xml_parse($parser, $data, feof($fp))) {
   printf("XML error: %s at line %d while parsing entity %s
\n",
   xml_error_string(xml_get_error_code($parser)),
   xml_get_current_line_number($parser),
$openEntityNames);
   xml_parser_free($parser);
   return false;
   }
   }
   xml_parser_free($parser);
   return true;
   }
   return false;
}


function new_xml_parser($file)
{
   global $parser_file;

   $xml_parser = xml_parser_create();
   xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1);
   xml_set_element_handler($xml_parser, "startElement", "endElement");
   xml_set_character_data_handler($xml_parser, "characterData");
   xml_set_processing_instruction_handler($xml_parser, "PIHandler");
   xml_set_default_handler($xml_parser, "defaultHandler");
   xml_set_external_entity_ref_handler($xml_parser,
"externalEntityRefHandler");
  
   if (!($fp = @fopen($file, "r"))) {
   return false;
   }
   if (!is_array($parser_file)) {
   settype($parser_file, "array");
   }
   $parser_file[$xml_parser] = $file;
   return array($xml_parser, $fp);
}

if (!(list($xml_parser, $fp) = new_xml_parser($file))) {
   die("could not open XML input");
}

echo "";
while ($data = fread($fp, 4096)) {
   if (!xml_parse($xml_parser, $data, feof($fp))) {
   die(sprintf("XML error: %s at line %d\n",
   xml_error_string(xml_get_error_code($xml_parser)),
   xml_get_current_line_number($xml_parser)));
   }
}
echo "";
echo "parse complete\n";
xml_parser_free($xml_parser);

?>

PARSER2


$name,"attrs"=>$attrs); 
   array_push($stack,$tag);
 
}

function cdata($parser, $cdata)
{
   global $stack,$i;
  
   if(trim($cdata))
   {   
   $stack[count($stack)-1]['cdata']=$cdata;   
   }
}

function endTag($parser, $name)
{
   global $stack; 
   $stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
   array_pop($stack);
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");

$data = xml_parse($xml_parser,file_get_contents($file));
if(!$data) {
   die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}

xml_parser_free($xml_parser);

print("\n");
print_r($stack);
print("\n");
?>



Here is the xml file I used to test:



]>

   
   &testEnt;
   


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



[PHP] Re: Parsing PHP variables in XML document

2006-02-26 Thread Bogdan Ribic

Ivan,

Did you try entering the code with debugger, or at least printing out 
what output buffer was holding, ie $content var in my example? Can you 
post exact code? Also, is short_tags turned on or off in php.ini? If it 
is on, php will get confused on first line of your xml file, it will 
think that 

In your original code you were calling the parser that was expecting 
$foo3 to be set, but you were setting the $foo3 *after* parsing, are you 
sure you're not making a mistake like that again?


Ivan Nedialkov wrote:

Well isn't there a way instead of using only variables, to use sth like

I tried it but it doesnt work
The parser returns blank! 


--

   Open source PHP code generator for DB operations
   http://sourceforge.net/projects/bfrcg/

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



[PHP] Re: Parsing PHP variables in XML document

2006-02-26 Thread Ivan Nedialkov
Well isn't there a way instead of using only variables, to use sth like

I tried it but it doesnt work
The parser returns blank! 

On Sun, 2006-02-26 at 12:02 +0100, Bogdan Ribic wrote:
> Hmmm, come to think of it, it would only work if short_open_tags ini 
> directive is turned OFF, which in most cases it won't be :(
> 
> Bogdan Ribic wrote:
> > Hi Ivan,
> > 
> >   You might be able to use output buffering in conjunction with 
> > including your xml file. Something like:
> > 
> > ob_start();
> > include $xml_file;
> > $content = ob_end_flush();
> > 
> >   and then parse the $content string. If you are doing this from within 
> > a function and you want access to global variables, you should import 
> > all global variables first, via extract($GLOBALS);
> > 
> >   Btw, this is just an idea, and untested - use at your own risk :)
> > 
> > Boban.
> 
> 
> 
> 

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



Re: [PHP] Re: Parsing PHP variables in XML document

2006-02-26 Thread chris smith
On 2/26/06, Bogdan Ribic <[EMAIL PROTECTED]> wrote:
> Hmmm, come to think of it, it would only work if short_open_tags ini
> directive is turned OFF, which in most cases it won't be :(

You can turn it off with a htaccess file.

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



[PHP] Re: Parsing PHP variables in XML document

2006-02-26 Thread Bogdan Ribic
Hmmm, come to think of it, it would only work if short_open_tags ini 
directive is turned OFF, which in most cases it won't be :(


Bogdan Ribic wrote:

Hi Ivan,

  You might be able to use output buffering in conjunction with 
including your xml file. Something like:


ob_start();
include $xml_file;
$content = ob_end_flush();

  and then parse the $content string. If you are doing this from within 
a function and you want access to global variables, you should import 
all global variables first, via extract($GLOBALS);


  Btw, this is just an idea, and untested - use at your own risk :)

Boban.





--

   Open source PHP code generator for DB operations
   http://sourceforge.net/projects/bfrcg/

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



[PHP] Re: Parsing PHP variables in XML document

2006-02-26 Thread Bogdan Ribic

Hi Ivan,

  You might be able to use output buffering in conjunction with 
including your xml file. Something like:


ob_start();
include $xml_file;
$content = ob_end_flush();

  and then parse the $content string. If you are doing this from within 
a function and you want access to global variables, you should import 
all global variables first, via extract($GLOBALS);


  Btw, this is just an idea, and untested - use at your own risk :)

Boban.


Ivan Nedialkov wrote:

Hi,

I have the following problem. I want to import data into my site via PHP
XML Parser, but I also want to include php string variables into
the .xml file and when the xml file is parsed the variables are replaced
whit the corresponding string.

So far all my attempts have been unsuccessful.

Here is the parser i have used

  
   function XMLParser($xml_file)

   {
   $this->filename = $xml_file;
   $this->xml = xml_parser_create();
   xml_set_object($this->xml, $this);
   xml_set_element_handler($this->xml, 'startHandler',
'endHandler');
   xml_set_character_data_handler($this->xml, 'dataHandler');
   $this->parse($xml_file);
   }
  
   function parse($xml_file)

   {
   if (!($fp = fopen($xml_file, 'r'))) {
 die('Cannot open XML data file: '.$xml_file);
   return false;
   }

   $bytes_to_parse = 512;

   while ($data = fread($fp, $bytes_to_parse)) {
   $parse = xml_parse($this->xml, $data, feof($fp));
  
   if (!$parse) {

   die(sprintf("XML error: %s at line %d",
   xml_error_string(xml_get_error_code($this->xml)),
   xml_get_current_line_number($this->xml)));
   xml_parser_free($this->xml
 );
   }
   }

   return true;
   }
  
   function startHandler($parser, $name, $attributes)

   {
   $data['name'] = $name;
   if ($attributes) { $data['attributes'] = $attributes; }
   $this->data[] = $data;
   }

   function dataHandler($parser, $data)
   {
   if ($data = trim($data)) {
   $index = count($this->data) - 1;
   // begin multi-line bug fix (use the .= operator)
   $this->data[$index]['content'] .= $data;
   // end multi-line bug fix
   }
   }

   function endHandler($parser, $name)
   {
   if (count($this->data) > 1) {
   $data = array_pop($this->data);
   $index = count($this->data) - 1;
   $this->data[$index]['child'][] = $data;
   }
   }
}



$url = 'data.xml';
$myFile = new XMLParser($url);

echo "";
print_r($myFile->data);
echo "";

$foo3 = "foo3";
?>

here is a sample XML file




]>



foo1


foo2





foo4


foo5



and what I get is:

Array
(
[0] => Array
(
[name] => DOCUMENT
[child] => Array
(
[0] => Array
(
[name] => DATA
[content] => foo1
)

[1] => Array
(
[name] => DATA
[content] => foo2
)

[2] => Array
(
[name] => DATA
)

[3] => Array
(
[name] => DATA
[content] => foo4
)

[4] => Array
(
[name] => DATA
[content] => foo5
)

)

)

)

So I want $myFile->data[0][child][2][content] to be equal to $foo3



   



--

   Open source PHP code generator for DB operations
   http://sourceforge.net/projects/bfrcg/

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



Re: [PHP] Re: Parsing HTML

2006-02-16 Thread Richard Lynch
On Thu, February 16, 2006 1:20 pm, Boby wrote:
> Jay Blanchard wrote:
>>> I need to extract news items from several news sites.
>  >> ...
>>> Can anybody please give me some pointers?
>>
>> Can you be more specific here? This is awfully broad.
>
> I'll give an example:
>
> Let's say I want to extract some news-items from the www.CNN.com web
> page (If you visit CNN's page, you can see the 'MORE NEWS' block at
> the
> right side).
>
> I know how to extract the news-items (or any other data in the page)
> using regular expressions, but I wonder if there are other ways. The
> code I'm writing will be maintained by other people in the future, and
> perhaps regular expressions won't be easy for them to update when the
> site changes its format.
>
> Can somebody please give me a short overview of the different ways of
> extracting data from HTML?
>
> I hope my question is clear enough now.

First, bypass the problem entirely, and look for an RSS / XML feed of
the same content.

Or a SOAP source of the content.

Or RPC.

Or WebDAV.

Or *anything* but web-scraping and parsing HTML, which should be your
"last resort"

If Regex seems high-maintenance, consider using just strpos and
explode and other simple string functions.

Most of the time, what you want in web-scrape looks like this:


TONS OF CRAP YOU DON'T CARE ABOUT,
LINE AFTER LINE,
PAGE AFTER PAGE...

• Melting
of Atlantic glaciers speeds up• U.S.: Iraqi death
squad members detained• U.N.: Close Gitmo, free
or try detainees | http://i.a.cnn.net/cnn/.element/img/1.3/misc/icon.wd.watch.white.gif";
alt="WATCH" width="39" height="14" hspace="0" vspace="0" border="0"
class="cnnWatchBtn">• Bush OK with Cheney's
story on shooting | Shooting
timeline• 360° Blog: 
Massive morgue
outside New Orleans rests in peace• White House
urged to review sale of U.S. ports to Arab
firm• Watch:
 Volunteers
build hope, homes on the bayou | Read• Watch:  Rings?
Check. Vows? Check. Caskets? Check.• New Bond
film finds its villain

RE: [PHP] Re: Parsing HTML

2006-02-16 Thread Jay Blanchard
[snip]
Let's say I want to extract some news-items from the www.CNN.com web 
page (If you visit CNN's page, you can see the 'MORE NEWS' block at the 
right side).

I know how to extract the news-items (or any other data in the page) 
using regular expressions, but I wonder if there are other ways. The 
code I'm writing will be maintained by other people in the future, and 
perhaps regular expressions won't be easy for them to update when the 
site changes its format.

Can somebody please give me a short overview of the different ways of 
extracting data from HTML?

I hope my question is clear enough now.
[/snip]

This was clear (and just as broad) before, but the answer is going to be
very broad. Have you looked at RSS feeds?

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



[PHP] Re: Parsing HTML

2006-02-16 Thread Boby

Jay Blanchard wrote:

I need to extract news items from several news sites.

>> ...

Can anybody please give me some pointers?


Can you be more specific here? This is awfully broad.


I'll give an example:

Let's say I want to extract some news-items from the www.CNN.com web 
page (If you visit CNN's page, you can see the 'MORE NEWS' block at the 
right side).


I know how to extract the news-items (or any other data in the page) 
using regular expressions, but I wonder if there are other ways. The 
code I'm writing will be maintained by other people in the future, and 
perhaps regular expressions won't be easy for them to update when the 
site changes its format.


Can somebody please give me a short overview of the different ways of 
extracting data from HTML?


I hope my question is clear enough now.

TIA.

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



[PHP] Re: Parsing HTML

2006-02-16 Thread Rafael
	If all you want is to "parse" HTML code, then you could treat it as 
XML, of course, that would assume that the sites are all well XHTML 
formed.  Other than that, I can only thing on PCRE.


Boby wrote:

I need to extract news items from several news sites.

In order to do that, I need to parse the HTML data.

I know how to use Regular Expressions, but I wonder if there are other 
ways to do that.

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
[EMAIL PROTECTED]
http://www.innox.com.mx

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



Re: [PHP] Re: Parsing MS-WORD docs

2005-09-09 Thread Rory Browne
If it simply for searching keywords and/or CV's, then wvWare will
probably do the job fine. I would suggest you retain the documents in
their original format however, so that the formatting and certain
elements that wvWare can't handle will remain when the CV is manually
viewed.



On 9/9/05, Shafiq Rehman <[EMAIL PROTECTED]> wrote:
> Hello,
> 
> Thanx to all of you for excellent suggestions. I am using Linux as OS and I
> want to parse the CVs and place in db for fulltext search. I think wvWare
> will work a lot for my case.
> 
> Thanx again.
> 
> On 9/8/05, Ben Ramsey <[EMAIL PROTECTED]> wrote:
> >
> > zzapper wrote:
> > >>On Wed, September 7, 2005 7:39 am, Shafiq Rehman wrote:
> > >>
> > >>>Hello,
> > >>>
> > >>>I want to parse the .doc files with PHP. Anybody have some idea
> > regarding
> > >>>this problem.
> > >>>
> > >>>Your help regarding this matter is really appreciated
> > >>>
> > >
> > > Also consider antiword
> > >
> >
> > And also:
> >
> > wvWare: http://wvware.sourceforge.net/
> > Word2x: http://word2x.sourceforge.net/
> >
> > --
> > Ben Ramsey
> > http://benramsey.com/
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> 
> --
> *** phpgurru.com  [A php resource provider] ***
> 
> \\\|///
> \\ - - //
> ( @ @ ) PHP is too logical for my brain
> +---oOOo-(_)-oOOo--+
> | Mian Shafiq ur Rehman
> | phpgurru.com  [A php resource provider]
> | 107 B, New Town, Multan Road
> | Lahore Pakistan
> |
> | Mobile: 0300 423 9385
> |
> | ooo0 http://www.phpgurru.com
> | ( ) 0ooo E-Mail: [EMAIL PROTECTED]
> +---\ (( )--+
> \_) ) /
> (_/
> 
>

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



Re: [PHP] Re: Parsing MS-WORD docs

2005-09-08 Thread Shafiq Rehman
Hello,

Thanx to all of you for excellent suggestions. I am using Linux as OS and I 
want to parse the CVs and place in db for fulltext search. I think wvWare 
will work a lot for my case.

Thanx again.

On 9/8/05, Ben Ramsey <[EMAIL PROTECTED]> wrote:
> 
> zzapper wrote:
> >>On Wed, September 7, 2005 7:39 am, Shafiq Rehman wrote:
> >>
> >>>Hello,
> >>>
> >>>I want to parse the .doc files with PHP. Anybody have some idea 
> regarding
> >>>this problem.
> >>>
> >>>Your help regarding this matter is really appreciated
> >>>
> >
> > Also consider antiword
> >
> 
> And also:
> 
> wvWare: http://wvware.sourceforge.net/
> Word2x: http://word2x.sourceforge.net/
> 
> --
> Ben Ramsey
> http://benramsey.com/
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
*** phpgurru.com  [A php resource provider] ***

\\\|///
\\ - - //
( @ @ ) PHP is too logical for my brain
+---oOOo-(_)-oOOo--+
| Mian Shafiq ur Rehman
| phpgurru.com  [A php resource provider]
| 107 B, New Town, Multan Road
| Lahore Pakistan
|
| Mobile: 0300 423 9385
|
| ooo0 http://www.phpgurru.com
| ( ) 0ooo E-Mail: [EMAIL PROTECTED]
+---\ (( )--+
\_) ) /
(_/


[PHP] Re: Parsing MS-WORD docs

2005-09-08 Thread Ben Ramsey

zzapper wrote:

On Wed, September 7, 2005 7:39 am, Shafiq Rehman wrote:


Hello,

I want to parse the .doc files with PHP. Anybody have some idea regarding
this problem.

Your help regarding this matter is really appreciated



Also consider antiword



And also:

wvWare: http://wvware.sourceforge.net/
Word2x: http://word2x.sourceforge.net/

--
Ben Ramsey
http://benramsey.com/

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



[PHP] Re: Parsing MS-WORD docs

2005-09-07 Thread zzapper
On Wed, 7 Sep 2005 09:18:03 +0100 (BST),  wrote:

>
>On Wed, September 7, 2005 7:39 am, Shafiq Rehman wrote:
>> Hello,
>>
>> I want to parse the .doc files with PHP. Anybody have some idea regarding
>> this problem.
>>
>> Your help regarding this matter is really appreciated
>>
>> Regards
>> --
>>
>> PHP is too logical for my brain (http://www.phpgurru.com)
>>
>
>Hello,
>
>Take a look over at SquirrelMail. http://www.squirrelmail.org/
>
>In thier Plugins section they have a script that parses all sorts of
>documents. Could be a start to build your own - however this needs a
>couple of extra packages (when installed in Unix).
>
Also consider antiword



-- 
zzapper
Success for Techies and Vim,Zsh tips
http://SuccessTheory.com/

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



[PHP] Re: parsing useragent string without get_browser

2005-08-25 Thread I. Gray

The problem is I haven't seen any examples of this in php.

The best I have come up with is the following. I know the code is pants, 
but it works. I am sure people out there can think of a better way of 
doing it-


$ua = $logInfo[useragent];
		if ( ereg("Firefox/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", 
$ua, $array)) {$browser = $array[0];}
		if ( ereg("MSIE [0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", 
$ua, $array)) {$browser = $array[0];}
		if ( 
ereg("Bloglines/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, 
$array)) {$browser = $array[0];}
		if ( 
ereg("Amfibibot/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, 
$array)) {$browser = $array[0];}
		if ( ereg("msnbot/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", 
$ua, $array)) {$browser = $array[0];}
		if ( 
ereg("Googlebot/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, 
$array)) {$browser = $array[0];}
		if ( ereg("Safari/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", 
$ua, $array)) {$browser = $array[0];}
		if ( 
ereg("Konqueror/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, 
$array)) {$browser = $array[0];}
		if ( ereg("Netscape/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", 
$ua, $array)) {$browser = $array[0];}
		if ( 
ereg("Thunderbird/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", 
$ua, $array)) {$browser = $array[0];}
		if		(strpos($ua, "Web RSS Reader")!== FALSE) {$browser = "Web RSS 
Reader";}

if  (strpos($ua, "BDFetch")!== FALSE) {$browser = 
"BDFetch";}
		if		(strpos($ua, "www.almaden.ibm.com/cs/crawler")!== FALSE) {$browser 
= "Web Fountain";}

if  (strpos($ua, "sohu-search")!== FALSE) {$browser = 
"Sohu Search";}
if  (strpos($ua, "Yahoo! Slurp")!== FALSE) {$browser = 
"Yahoo! Slurp";}
if  (strpos($ua, "Windows NT 5.1")) {$platform = 
"Windows XP";}
elseif  (strpos($ua, "Windows NT 5.0")) {$platform = "Windows 
2000";}
		elseif	(strpos($ua, "Windows 98") OR strpos($ua, "Win98")) {$platform 
= "Windows 98";}
		elseif	(strpos($ua, "Windows 95") OR strpos($ua, "Win95")) {$platform 
= "Windows 95";}
		elseif	(strpos($ua, "Win16") OR strpos($ua, "Windows 3.1")) {$platform 
= "Windows 3.1";}

elseif  (strpos($ua, "Mac OS X")) {$platform = "Mac OSX";}
elseif  (strpos($ua, "Linux")) {$platform = "Linux";}

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



Re: [PHP] Re: Parsing search strings from referer urls?

2005-01-26 Thread Jennifer Goodie

 -- Original message --
From: Jason Barnett <[EMAIL PROTECTED]>
> T.J. Mahaffey wrote:
> > First time post, please be gentle.
> 
> You will probably find parse_url() to be useful:
> http://www.php.net/manual/en/function.parse-url.php
> 
>  
> $url = 
> "http://username:[EMAIL 
> PROTECTED]/path?arg=value&arg2=value&arg3=value3#anchor"
> ;
> 
> $parts = parse_url($url);
> $args = explode('&', $parts['query']);
> 
> for($i = 0; $i < sizeof($args); $i++) {
>list($key, $value) = explode('=', $args[$i]);
>$query[$key] = urldecode($value);
> }
> 
> print_r($query);
> 
> ?>
parse_str will take care of turning the query string into key/value pairs
http://us2.php.net/manual/en/function.parse-str.php

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



[PHP] Re: Parsing search strings from referer urls?

2005-01-26 Thread Jason Barnett
T.J. Mahaffey wrote:
First time post, please be gentle.
I'd like to be able to extract search strings from referer urls that come from 
search engines. (via php,
of course) For example, http://www.google.com/search?q=foo+bar&ie=UTF-8&oe=UTF-8
Now, I realize one might employ grep to pull out this information and its easy 
for a human to examine
a url like the one above, but I'd like to programmatically present a nice, tidy 
list of search words used
to generate the url.
My gut says that one would need to write a function for each major search 
engine to parse out this
information since each engine is unique in how it builds the url. However, I 
thought after poring over
the manual and online docs/list and not finding a solution, and before I went 
off and reinvented the
wheel, I would float the question and see what you fine folks have to say about 
the subject.
You will probably find parse_url() to be useful:
http://www.php.net/manual/en/function.parse-url.php

$url = 
"http://username:[EMAIL PROTECTED]/path?arg=value&arg2=value&arg3=value3#anchor";

$parts = parse_url($url);
$args = explode('&', $parts['query']);
for($i = 0; $i < sizeof($args); $i++) {
  list($key, $value) = explode('=', $args[$i]);
  $query[$key] = urldecode($value);
}
print_r($query);
?>
--
Teach a man to fish...
NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://www.php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY | 
http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins

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


[PHP] Re: parsing /'s in urls

2004-11-12 Thread Sebastian Mendel
[EMAIL PROTECTED] wrote:
My host recently upgraded PHP.  I had a script, download.php, that would
work like this
http://www.myhost.com/download.php/30/file.torrent
the download.php script would take the 30, look up the real filename in the
database, and readfile() it back.  this was a great setup because the
browser just thought it was accessing a direct link to a file.
But now download.php/30/file.torrent results in a 404.
Is this something I can change back?
this is an apache related thing
http://httpd.apache.org/docs-2.0/mod/core.html#acceptpathinfo
--
Sebastian Mendel
www.sebastianmendel.de www.warzonez.de www.tekkno4u.de www.nofetish.com
www.sf.net/projects/phpdatetimewww.sf.net/projects/phptimesheet
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Parsing

2004-10-27 Thread Jason Barnett
Jerry Swanson wrote:
I have huge html file.  I want to parse the data and get everything between
 and 
What function is good for this purpose?
TH

preg_match() is a good choice.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: parsing a string

2004-10-20 Thread Dan McCullough
I tried the print_r on $res.  The preg_match does the first set fine.
So I get:
 
Campus
Bob (Williams)
 
the second one starts 
-
Address123 Main St
-
CityOxford
 
 
and so on
[EMAIL PROTECTED] wrote:
preg_match('#([^|]*)[|]+([^|]*)~[\\]+(([^\\]*)~[\\]+)+#Ui', $string, $res);
use print_r on the $res to check for the results (I'm not 100% sure if
they'll come out in $res[2], $res[3], $res[4], etc. or in $res[4][0],
$res[4][1], etc.


> I knew I shouldnt have abreviated the string.
> here is the string sorry I kinda flubbed on the last string
> "LocationCampus~\\n-\nNameBob
> Williams~\\n-\nAddress123 Main
> St~\\n-\n..."
>
> the ... is a very long list.
>
> how does this change the preg_match
>
> "M. Sokolewicz" wrote:
> Not sure what you want exactly, but here's a way using regexps to
> retrieve the strings seperatly:
> $string = 'CampusBob (Williams)~\toms more
> crap)~\blah blah blah)~\';
> preg_match('#([^|]*)[|]+([^|]*)~[\]+([^\]*)~[\]+([^\]*)~[\]+#Ui',
> $string, $res);
> $campus = $res[1];
> $bob = $res[2];
> $crap = $res[3];
> $blah = $res[4];
> ?>
> Now, if you wanted the positions... then something like this would work:
>
> $string = 'CampusBob (Williams)~\toms more
> crap)~\blah blah blah)~\';
> preg_match('#([^|]*)[|]+([^|]*)~[\]+([^\]*)~[\]+([^\]*)~[\]+#Ui',
> $string, $res);
>
> $campus = strpos($string, $res[1]);
> $bob = strpos($string, $res[2]);
> $crap = strpos($string, $res[3]);
> $blah = strpos($string, $res[4]);
> ?>
>
> Dan McCullough wrote:
>> Hey everyone
>>
>> Having a bit of trouble with something.
>>
>> I have a string which has known patterns.
>>
>> $string"CampusBob (Williams)~\toms more
>> crap)~\blah blah blah)~\";
>>
>> What I am looking for is
>>
>> Location which is Campus
>> Location Name which is Bob (Williams)
>>
>> Help?
>>
>>
>>
>> -
>> Do you Yahoo!?
>> vote.yahoo.com - Register online to vote today!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> 
> "Theres no such thing as a problem unless the servers are on fire!"
>
>
> -
> Do you Yahoo!?
> Yahoo! Mail - Helps protect you from nasty viruses.




"Theres no such thing as a problem unless the servers are on fire!"


-
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.

Re: [PHP] Re: parsing a string

2004-10-20 Thread Dan McCullough
I knew I shouldnt have abreviated the string.
here is the string sorry I kinda flubbed on the last string
"LocationCampus~\\n-\nNameBob 
Williams~\\n-\nAddress123 Main St~\\n-\n..."
 
the ... is a very long list.
 
how does this change the preg_match

"M. Sokolewicz" <[EMAIL PROTECTED]> wrote:
Not sure what you want exactly, but here's a way using regexps to 
retrieve the strings seperatly:
$string = 'CampusBob (Williams)~\toms more 
crap)~\blah blah blah)~\';
preg_match('#([^|]*)[|]+([^|]*)~[\]+([^\]*)~[\]+([^\]*)~[\]+#Ui', 
$string, $res);
$campus = $res[1];
$bob = $res[2];
$crap = $res[3];
$blah = $res[4];
?>
Now, if you wanted the positions... then something like this would work:

$string = 'CampusBob (Williams)~\toms more 
crap)~\blah blah blah)~\';
preg_match('#([^|]*)[|]+([^|]*)~[\]+([^\]*)~[\]+([^\]*)~[\]+#Ui', 
$string, $res);

$campus = strpos($string, $res[1]);
$bob = strpos($string, $res[2]);
$crap = strpos($string, $res[3]);
$blah = strpos($string, $res[4]);
?>

Dan McCullough wrote:
> Hey everyone
> 
> Having a bit of trouble with something.
> 
> I have a string which has known patterns.
> 
> $string"CampusBob (Williams)~\toms more crap)~\blah blah 
> blah)~\";
> 
> What I am looking for is 
> 
> Location which is Campus
> Location Name which is Bob (Williams)
> 
> Help?
> 
> 
> 
> -
> Do you Yahoo!?
> vote.yahoo.com - Register online to vote today!

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




"Theres no such thing as a problem unless the servers are on fire!"


-
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.

[PHP] Re: parsing a string

2004-10-20 Thread M. Sokolewicz
Not sure what you want exactly, but here's a way using regexps to 
retrieve the strings seperatly:

$string = 'CampusBob (Williams)~\toms more 
crap)~\blah blah blah)~\';
preg_match('#([^|]*)[|]+([^|]*)~[\]+([^\]*)~[\]+([^\]*)~[\]+#Ui', 
$string, $res);
$campus = $res[1];
$bob = $res[2];
$crap = $res[3];
$blah = $res[4];
?>
Now, if you wanted the positions... then something like this would work:


$string = 'CampusBob (Williams)~\toms more 
crap)~\blah blah blah)~\';
preg_match('#([^|]*)[|]+([^|]*)~[\]+([^\]*)~[\]+([^\]*)~[\]+#Ui', 
$string, $res);

$campus = strpos($string, $res[1]);
$bob = strpos($string, $res[2]);
$crap = strpos($string, $res[3]);
$blah = strpos($string, $res[4]);
?>
Dan McCullough wrote:
Hey everyone
 
Having a bit of trouble with something.
 
I have a string which has known patterns.
 
$string"CampusBob (Williams)~\toms more crap)~\blah blah blah)~\";
 
What I am looking for is 
 
Location which is Campus
  Location Name which is Bob (Williams)
 
Help?
 


-
Do you Yahoo!?
vote.yahoo.com - Register online to vote today!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: parsing a string

2004-10-20 Thread Greg Beaver
Dan McCullough wrote:
Hey everyone
 
Having a bit of trouble with something.
 
I have a string which has known patterns.
 
$string"CampusBob (Williams)~\toms more crap)~\blah blah blah)~\";
 
What I am looking for is 
 
Location which is Campus
  Location Name which is Bob (Williams)
$x = explode('~', $string);
list($location, $name) = explode('', $x[0]);
Make sure that for each \ in the string, you use \\ (that's why there 
are 10 in my example.  If you have 5 \ you need 5 \\)

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


Re: [PHP] Re: Parsing error when XML version is mentioned

2004-07-25 Thread Justin French
On 26/07/2004, at 7:29 AM, Scrumpy wrote:
[EMAIL PROTECTED] (Suresh Manoharan) wrote in
news:[EMAIL PROTECTED]:
I am getting parse error [Parse error: parse error, unexpected
T_STRING  on line 1] when I use XML version info.

http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
http://www.w3.org/1999/xhtml"; xml:lang="en-US"
lang="en-US"> 
[snip]
Can you pls. help me understand why parsing error occurs and how to
avoid it.
I just start with "That's a workaround, not a solution.
The problem is that  is PHP code, which it isn't, 
hence the errors spit out by the PHP engine.

Solution 1:
Turn off short tags in your php.ini file, so that only  
will turn on the PHP engine.  This may require a large rewrite of 
existing scripts though.

Solution 2:
Instead of

on line 1, use
'; ?>
In other words, let PHP's engine echo the XML declaration, avoiding the 
PHP parsing errors.

Regards
---
Justin French
http://indent.com.au
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Parsing error when XML version is mentioned

2004-07-25 Thread Scrumpy
[EMAIL PROTECTED] (Suresh Manoharan) wrote in
news:[EMAIL PROTECTED]: 

> I am getting parse error [Parse error: parse error, unexpected
> T_STRING  on line 1] when I use XML version info.
> 
>
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
>http://www.w3.org/1999/xhtml"; xml:lang="en-US"
>lang="en-US"> 
[snip]
> Can you pls. help me understand why parsing error occurs and how to
> avoid it.

I just start with "http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: parsing xml the right way

2004-04-02 Thread Justin Patrin
Merlin wrote:

Hi there,

I think I am parsing xml documents the wrong way.
There must be a better way to access the results laterone like objects.
For example I would like to search in a free form for a city name
inside an xml document and php should return the country name
and continent.
This is the xml structure:

Andorra
AD
Europe

Encamp
Escaldes-Engordany
Ordino
Soldeu


Has anybody a good hint for me?

Thanx in advance,

Merlin
I created this class a short while ago that parses all of your XML into 
an easily usable Associative array structure. It extends 
PEAR::XML_Parse, so you need that as well.

http://reversefold.com/~papercrane/XML_Parser_Assoc/Assoc.phps
http://pear.php.net/package/XML_Parser
--
paperCrane 
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: parsing xml the right way

2004-04-02 Thread trlists
On 2 Apr 2004 Aidan Lister wrote:

> Wait until you have installed PHP5, then use the simplexml library.

I will shortly have the same questions about ways to parse XML, and I 
can't use PHP 5 -- it's a production environment and the PTB are not 
going to move to something that is that recently released.  ANy other 
suggestions?

--
Tom

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



[PHP] Re: parsing xml the right way

2004-04-02 Thread Aidan Lister
Wait until you have installed PHP5, then use the simplexml library.

You have not showed us any code, how are we to tell you if you are doing it
the right or wrong way?

"Merlin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi there,
>
> I think I am parsing xml documents the wrong way.
> There must be a better way to access the results laterone like objects.
>
> For example I would like to search in a free form for a city name
> inside an xml document and php should return the country name
> and continent.
>
> This is the xml structure:
> 
> Andorra
> AD
> Europe
> 
> Encamp
> Escaldes-Engordany
> Ordino
> Soldeu
> 
> 
>
> Has anybody a good hint for me?
>
> Thanx in advance,
>
> Merlin

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



[PHP] Re: parsing entities

2004-03-30 Thread Jason Barnett
First of all, if you have the option to upgrade you might want to check 
out PHP5.  SimpleXML really makes it easy to parse xml files.  If PHP4 
is your platform of choice, check out PEAR's XML_Parser package.

The entities can't be handle with xml_set_default_handler because some 
entities are inside an attribute (title, href) and are then printed before 
the tag. How can I fix this?
In order to parse xml attributes you should use xml_set_element_handler.
http://www.php.net/manual/en/function.xml-set-element-handler.php
I don't understand how those other functions work:
http://www.php.net/manual/en/function.xml-set-external-entity-ref-handler.php
http://www.php.net/manual/en/function.xml-set-unparsed-entity-decl-handler.php
Haven't used these, maybe others can help?

Could it be the solution?

Another problem is that it changes tags like  by .
Is there a way to avoid this?
With xml_set_element_handler you tell the parser to use callback 
functions for your start tag / end tag.  You can set up your callback 
functions to handle img tags special.



+ Cheers

(PS - I am also curious about how the fuction 
xml_set_start_namespace_decl_handler() work.
Does someone know some informations about?)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: parsing variables inside a variable?

2004-01-30 Thread John W. Holmes
From: "Justin Patrin" <[EMAIL PROTECTED]>

> >>What you need to understand is that the string parsing for variables
> >>only happens when the string is actually in your script. When you
> >>dynamically create a string (or get it from a DB) it's just a string of
> >>characters in memory and is *not* parsed.
> >>
> >>To do something like this, you would have to use one of a few things.
> >>The first would be to use some kind of search and replace to replace
> >>those variables with what you really want.
> >>
> >>$text = str_replace('$name', $name, $text);
> >>
> >>That's fairly simple and could even be done for multiple variables.
> >>
> >>foreach(array('name', 'price') as $varName) {
> >>   //yes, the $$ is correct
> >>   $text = str_replace('$'.$varName, $$varName, $text);
> >>}
> >>
> >>You could also use a regular expression if you *really* wanted to, but
> >>what's above is easier.

For a regular expression example of how to do this:



Where "$str" is what's retrieved from the database with the "variables" in
it.

---John Holmes...

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



[PHP] Re: parsing variables inside a variable?

2004-01-30 Thread Justin Patrin
Jimbo wrote:

Thanks Justin I was aware of that method but wanted to avoid it if possible,
however another person explained to me that eval() can be used to force PHP
to evaluate (i.e. parse) the variables, just thought I'd let you know for
your future reference.
James

--

www.jholt.co.uk : affordable business website solutions
www.htpshareware.com : software for the disorganized

"You don't needs eyes to see, you need vision" - Maxi Jazz

"Justin Patrin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Jimbo wrote:


I query and use mysql_fetch_array to get the data into an associative
array.

I then build a string and output it like this:
echo "blah blah ".$row["thecolumn"]." blah blah";
What you need to understand is that the string parsing for variables
only happens when the string is actually in your script. When you
dynamically create a string (or get it from a DB) it's just a string of
characters in memory and is *not* parsed.
To do something like this, you would have to use one of a few things.
The first would be to use some kind of search and replace to replace
those variables with what you really want.
$text = str_replace('$name', $name, $text);

That's fairly simple and could even be done for multiple variables.

foreach(array('name', 'price') as $varName) {
  //yes, the $$ is correct
  $text = str_replace('$'.$varName, $$varName, $text);
}
You could also use a regular expression if you *really* wanted to, but
what's above is easier.
--
paperCrane 
Well, I would have mentioned eval(), but you have to put PHP code in 
there instead of just strings. For example, "Hello $name." would have to 
become.

'return "Hello $name."';

or

'return \'Hello \'.$name.\'.\'';

If you eval a string with "Hello $name." in it, you will get a parse 
error. For readability, I would think that using str_replace to replace 
specific variables would be better.

Actually, it would be even better if you used a templating system to do 
this kind of thing, such as Smarty. That way you don't have to worry 
about variable replacement, but your strings can still be easily edited.

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


[PHP] Re: parsing variables inside a variable?

2004-01-30 Thread jimbo
Thanks Justin I was aware of that method but wanted to avoid it if possible,
however another person explained to me that eval() can be used to force PHP
to evaluate (i.e. parse) the variables, just thought I'd let you know for
your future reference.

James

--

www.jholt.co.uk : affordable business website solutions
www.htpshareware.com : software for the disorganized


"You don't needs eyes to see, you need vision" - Maxi Jazz

"Justin Patrin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Jimbo wrote:
>
> >
> > I query and use mysql_fetch_array to get the data into an associative
array.
> > I then build a string and output it like this:
> > echo "blah blah ".$row["thecolumn"]." blah blah";
> >
>
> What you need to understand is that the string parsing for variables
> only happens when the string is actually in your script. When you
> dynamically create a string (or get it from a DB) it's just a string of
> characters in memory and is *not* parsed.
>
> To do something like this, you would have to use one of a few things.
> The first would be to use some kind of search and replace to replace
> those variables with what you really want.
>
> $text = str_replace('$name', $name, $text);
>
> That's fairly simple and could even be done for multiple variables.
>
> foreach(array('name', 'price') as $varName) {
>//yes, the $$ is correct
>$text = str_replace('$'.$varName, $$varName, $text);
> }
>
> You could also use a regular expression if you *really* wanted to, but
> what's above is easier.
>
> --
> paperCrane 

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



[PHP] Re: parsing variables inside a variable?

2004-01-29 Thread Justin Patrin
Jimbo wrote:

I query and use mysql_fetch_array to get the data into an associative array.
I then build a string and output it like this:
echo "blah blah ".$row["thecolumn"]." blah blah";
What you need to understand is that the string parsing for variables 
only happens when the string is actually in your script. When you 
dynamically create a string (or get it from a DB) it's just a string of 
characters in memory and is *not* parsed.

To do something like this, you would have to use one of a few things. 
The first would be to use some kind of search and replace to replace 
those variables with what you really want.

$text = str_replace('$name', $name, $text);

That's fairly simple and could even be done for multiple variables.

foreach(array('name', 'price') as $varName) {
  //yes, the $$ is correct
  $text = str_replace('$'.$varName, $$varName, $text);
}
You could also use a regular expression if you *really* wanted to, but 
what's above is easier.

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


[PHP] Re: Parsing specific portions of XML files

2003-10-28 Thread Ian Williams
If it's anything like the Microsoft XML DOM object, you can use an XPath
query to select the portion of the XML file that you want.

"Ryan Thompson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
I'm stumped. I think it's just the logic I can't figure out. I have a file
formatted for Docbook in XML. I'm trying to figure out a way to parse a
specifice portion of an itemizedlist.

It's for a change log. I want users to be able to view changes made to just
one version and possibly for all. I can't use multiple change logs cause it
the same file is used to make the text version that goes into the release
documentation.

Anyone got any ideas that can give me a push in the right direction.

--
Ryan Thompson
[EMAIL PROTECTED]
http://osgw.sourceforge.net
==
"A computer scientist is someone who fixes
 things that aren't broken" --Unknown

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



[PHP] Re: parsing domains

2003-08-28 Thread Kae Verens
Collegesucks.Com Mike wrote:
Quick question...

I parse domains in my scripts like this to get the .domain.com out of www.domain.com. However, if someone visits my site with just domain.com in the url, I get .com back as the parsed domain. How can I make it so I aways get the .domain.com no matter what they use?

Here is an example of what I use now...

$parseddomain = preg_replace('/.+?(\..+)/', '$1', $domain);


this should do it:
$parseddomain=preg_replace('/.*?([^.]*\.[^.]*)/','\\1',$domain);
Kae

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


Re: [PHP] Re: Parsing a local file

2003-07-29 Thread DvDmanDT
lol, yeah, guess so... Although, when you talk about these things, do you
say you must download a file from the client? Or that you must open the
remote logfile in your script? Damn, this is getting screwy...

-- 
// DvDmanDT
MSN: [EMAIL PROTECTED]
Mail: [EMAIL PROTECTED]
"Curt Zirzow" <[EMAIL PROTECTED]> skrev i meddelandet
news:[EMAIL PROTECTED]
> * Thus wrote DvDmanDT ([EMAIL PROTECTED]):
> > Also, it's a remote file you are trying to parse, not  a local...
> > local=server, remote=user... Like John linked, you must upload it...
Can't
> > do it other ways...
>
> I suppose in this case with local and remote defined this way it
> should be download instead of upload :)
>
> Curt
> -- 
> "I used to think I was indecisive, but now I'm not so sure."



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



Re: [PHP] Re: Parsing a local file

2003-07-29 Thread Curt Zirzow
* Thus wrote DvDmanDT ([EMAIL PROTECTED]):
> Also, it's a remote file you are trying to parse, not  a local...
> local=server, remote=user... Like John linked, you must upload it... Can't
> do it other ways...

I suppose in this case with local and remote defined this way it
should be download instead of upload :)

Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

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



[PHP] Re: Parsing a local file

2003-07-29 Thread DvDmanDT
Also, it's a remote file you are trying to parse, not  a local...
local=server, remote=user... Like John linked, you must upload it... Can't
do it other ways...

-- 
// DvDmanDT
MSN: [EMAIL PROTECTED]
Mail: [EMAIL PROTECTED]
"Jason D. Williard" <[EMAIL PROTECTED]> skrev i meddelandet
news:[EMAIL PROTECTED]
> I am trying to build script that will parse a file on the user's computer.
> There are 2 things that I am not quite sure about.
>
> 1) How to read a file on the user's computer, and not on the server.
>
> 2) How to parse a line similar to the one below:
>
> "7/29/2003" , "Report Title" , "Page" , "Agent Name" , "5200" , "30" ,
> "3:30" , "" , "" , ""
>
> Now, in this line, there are items that I would like to discard.  As well,
> there are items between the "s that I would like the parse further.  Below
> is how I would like it parsed
>
> "$month/$day/$year" , "DISCARD" , "DISCARD" , "DISCARD" , "$agentid" ,
> "$calls_taken" , "$avg_call_time" , "DISCARD" , "DISCARD" , "DISCARD"
>
>
> Any help would be appreciated.
>
> Thanks,
> Jason
>
>
>
>
>
>



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



[PHP] Re: Parsing PHP

2003-07-26 Thread Greg Beaver
Hi Nikhil,

There are a number of choices already out there.  In phpDocumentor 
(http://www.phpdoc.org) is a parser that is based on the tokenizer. 
Also available in PEAR CVS is the PHP_Parser, which is a generated 
parser based on PHP's own zend_language_parser.y 
(http://cvs.php.net/cvs.php/pear/PHP_Parser?login=2)

Regards,
Greg
--
phpDocumentor
http://www.phpdoc.org
Nikhil G. Daddikar wrote:
I am using PHP to develop and web app.

The app also has a scripting language for the *end user*. I was thinking 
if I could expose a very simple subset of PHP to them (foreach, 
if-then-else, variable assignments and comments) and then simply "eval" 
it. But I don't want them to use calls like system or do infinite loops 
etc. that will screw up the system.

I was thinking if I had a PHPparser that returns tokens, then I can 
eliminate the call to unwanted funtions, etc.

Any ideas on how I should proceed?

Thanks.






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


[PHP] Re: Parsing XML CDATA errors?

2003-03-31 Thread Lock Ct.
i think it should be 

line 43 : $person_data[$counter]["description"] .= $data;

wish you luck !



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



[PHP] Re: Parsing a directory for specific files

2003-01-10 Thread Tommy Jensehaugen
function get_file_list($dirName=".") {
 $list = array();
 $handle = opendir($dirName);
 while (false !== ($file = readdir($handle))) {
 /* Omit the '.' and the '..' directories. */
  if ((".."== $file) || ("."== $file)) continue;
  array_push($list, $file);
 }
 closedir($handle);
 return $list;
}

Then you have an array of the filenames.
If you use rsort($array), the 5 first elements will be the 5 most recent
ones.


tommy

"Dirk Van Lyrop" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi,
>
> does anybody know how to solve the following task?
>
> I'd like to generate a dynamic page, which contents come from txt-files.
> The files will be in a directory called content (from the page:
> ../content) and they are labeled with date and (within one day)
> increasing numbers,
> e.g. 20030108-1.txt, 20030108-2.txt, 20030108-3.txt, 20030109-1.txt,
> 20030110-1.txt, 20030110-2.txt
> The script should parse the file names and get the most recent five ones!
>
> The text inside should be included in the page -> but this is not the
> problem, the task mentioned above is the problem!
>
> Thx in advance for these who can deliever solutions or ideas!
>
> Dirk
>
>



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




[PHP] Re: Parsing an array from a posted form

2002-11-20 Thread Nick Eby
you can use the implode() function:

for ($z=0;$z wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi All :)
>
> I have a form that is being passed to a mail function when submitted. It
is
> working OK, except that I am having trouble with values from arrays such
as
> checkbox lists. For example, I have a list such as:
>
>  .eps
>  .jpg
>  .tif
>  .gif
>  .png
>  .psd
>  .bmp
>  other
>
> I am using something like:
>
> for ($z=0;$z   $graphicFormat = stripslashes($graphicFormat[$z]);
> }
>
> Which will return a count of the number of items in the array. What I want
> returned is a string of the values selected such as:
>
> "eps, gif, other"
>
> Any suggestions?
>
> Best Regards,
> verdon
>
> Ps. Please cc me as I am on digest mode
> Pps. Please excuse if my question is TOO fundamental
>



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




RE: [PHP] Re: Parsing HTML

2002-10-28 Thread Jay Blanchard
[snip]
What?!?  You're not awake at 4:30 in the morning writing code?!?  I
think the commitee will have to reconsider your geek club membership.  :)
[/snip]

How do you think that I knew the original post came in at that time?
ROFLMAO. Go ahead revoke my Geek Club card, the discounts no longer
work! :^]

Jay



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




RE: [PHP] Re: Parsing HTML

2002-10-28 Thread Jay Blanchard
[snip]
I did a search ...
[/snip]

My apologies Henry, I had just received a piece of disturbing news along
with starting my Monday at 4:30 CST with some database server problems. You
just happened to get in the line of fire.

Start with the regular expression functions in PHP. Once you have an
understanding of how they work you will start to figure it out. You will be
a better programmer for it. Once you have started to assemble your code,
post it with questions about the how's and why's. Most folks on this list
who are here to help will not take the "5 minutes" to write an untested
piece of code for you. They will attempt to point you in a particular
direction and teach you how to do it.

Jay



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




Re: [PHP] Re: Parsing HTML

2002-10-28 Thread John Nichel
What?!?  You're not awake at 4:30 in the morning writing code?!?  I 
think the commitee will have to reconsider your geek club membership.  :)

Jay Blanchard wrote:
[snip]
Thanks Jay, I am still a newbie and I will read the manual, thankyou for the
help.

Having an OK day in the UK .   
[/snip]

Henry your questions will get answered more quickly and accurately when you
provide

a. A clear explanation of the problem at hand
2. Proof that you have done some research on your own (show your work) [RTFM
or STFW]

Coming back with a "What..!!" will get you squat, it is insulting to those
who are here to help. Also your original post was about 4:30AM and your
follow-up "What..!!" was at 9AM ... on a Monday morning. Think
aboout that for a second.

HTH!

Jay







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




Re: [PHP] Re: Parsing HTML

2002-10-28 Thread Henry
I assure you that I am not trying to circumvent google's anything. I'm
trying to provide a HTML translation page tool for some of my visitors where
they will provide there own URL and a translation of some keywords will be
done for them. Thats all.

I never actually was going to flaunt googles terms and conditions and after
the replys from Rasmus I went away and looked into the mater. I agree whole
heartedly with what Rasmus and others said and will not be circumventing
APIs under any circumstance.

Henry

"John Nichel" <[EMAIL PROTECTED]> wrote in message
news:3DBD546D.3000500@;by-tor.com...
> The tools for you to execute the regular expression are there for you in
> the manual.  The actual regular expression that you're looking for is
> not a php issue.  And I can't say that I'm totally convinced that you're
> still not trying to circumvent google's TOS.
>
> Henry wrote:
> > What; nobody has anything to say about parsing HTML and doing search and
> > replaces!! Is there another news group that might be better suited? I do
> > want to do it PHP if I hadn't made that clear.
> >
> > Somebody, anybody, please help.
> >
> > "Henry" <[EMAIL PROTECTED]> wrote in message
> > news:20021028103849.2175.qmail@;pb1.pair.com...
> >
> >>Hi All,
> >>
> >>I would like to be able to do a serach and replace in a HTML document.
For
> >
> > a
> >
> >>list of words;
> >>
> >>for example:
> >>hello become buongiorno
> >>yes becomes si
> >>size become grossezza
> >>
> >>The problem is that if I change the word "size" without considering html
> >>tags and html comments in the case of inline javascripts I'll end up
with
> >>"broken" html.
> >>
> >>Is there a way to only do the search and replace outside the tags and
> >>comments.
> >>
> >>It is further complicated by the fact that I would still like to do the
> >>replacements within strings for example within meta tags!
> >>
> >>Any ideas.
> >>
> >>Henry
> >>
> >>
> >
> >
> >
> >
>
>



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




RE: [PHP] Re: Parsing HTML

2002-10-28 Thread Jon Haworth
Hi Henry,

> If it is so simple perhaps you might spend 5 
> minutes generating the regular expression to 
> use that will ignore the contents of tags save 
> for the contents of quotes within meta tags and 
> do the replace for an associative array of mappings.

http://google.com/search?q=regex+search+replace+outside+html+tags might be a
good way for you to pass the time while you're waiting for Jay to write your
program ;-)

Cheers
Jon

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




Re: [PHP] Re: Parsing HTML

2002-10-28 Thread Henry
I did a search and I remebered that I have previously seen some of your
work. In particlar your guide to CMS in evolt.org. Which I think is
absolutely wonderful. Thankyou for your help and I hope that I haven't gone
to far with my disingenuous comment posting.

I hadn't appreciated the time difference and do appreciate your help.

Thankyou.

Henry

"Jay Blanchard" <[EMAIL PROTECTED]> wrote in message
news:004001c27e95$1c4d2580$8102a8c0@;000347D72515...
> [snip]
> Thanks Jay, I am still a newbie and I will read the manual, thankyou for
the
> help.
>
> Having an OK day in the UK .   
> [/snip]
>
> Henry your questions will get answered more quickly and accurately when
you
> provide
>
> a. A clear explanation of the problem at hand
> 2. Proof that you have done some research on your own (show your work)
[RTFM
> or STFW]
>
> Coming back with a "What..!!" will get you squat, it is insulting to those
> who are here to help. Also your original post was about 4:30AM and your
> follow-up "What..!!" was at 9AM ... on a Monday morning. Think
> aboout that for a second.
>
> HTH!
>
> Jay
>
>



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




Re: [PHP] Re: Parsing HTML

2002-10-28 Thread Henry
Dear Jay,

I have now had a look in the FM and whilst it does help if you know how to
use regular expressions I think that you are being a little disingenuous.
Having to parse the HTML is more complicated than is suggest in your reply.
If it is so simple perhaps you might spend 5 minutes generating the regular
expression to use that will ignore the contents of tags save for the
contents of quotes within meta tags and do the replace for an associative
array of mappings.

Hope your day is getting better in Texas.

Henry

"Jay Blanchard" <[EMAIL PROTECTED]> wrote in message
news:003f01c27e93$87bc1da0$8102a8c0@;000347D72515...
> [snip]
> What; nobody has anything to say about parsing HTML and doing search and
> replaces!! Is there another news group that might be better suited? I do
> want to do it PHP if I hadn't made that clear.
>
> Somebody, anybody, please help.
> [/snip]
>
> What? No one wants to help someone who didn't search the manual for
regular
> expressions? Things like eregi_replace()?
>
> RTFM, this is very basic.
>
> Having a bad day in Texas... :^[ *grrr*
>
> Jay
>
>



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




RE: [PHP] Re: Parsing HTML

2002-10-28 Thread Jay Blanchard
[snip]
Thanks Jay, I am still a newbie and I will read the manual, thankyou for the
help.

Having an OK day in the UK .   
[/snip]

Henry your questions will get answered more quickly and accurately when you
provide

a. A clear explanation of the problem at hand
2. Proof that you have done some research on your own (show your work) [RTFM
or STFW]

Coming back with a "What..!!" will get you squat, it is insulting to those
who are here to help. Also your original post was about 4:30AM and your
follow-up "What..!!" was at 9AM ... on a Monday morning. Think
aboout that for a second.

HTH!

Jay



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




Re: [PHP] Re: Parsing HTML

2002-10-28 Thread John Nichel
The tools for you to execute the regular expression are there for you in 
the manual.  The actual regular expression that you're looking for is 
not a php issue.  And I can't say that I'm totally convinced that you're 
still not trying to circumvent google's TOS.

Henry wrote:
What; nobody has anything to say about parsing HTML and doing search and
replaces!! Is there another news group that might be better suited? I do
want to do it PHP if I hadn't made that clear.

Somebody, anybody, please help.

"Henry" <[EMAIL PROTECTED]> wrote in message
news:20021028103849.2175.qmail@;pb1.pair.com...


Hi All,

I would like to be able to do a serach and replace in a HTML document. For


a


list of words;

for example:
hello become buongiorno
yes becomes si
size become grossezza

The problem is that if I change the word "size" without considering html
tags and html comments in the case of inline javascripts I'll end up with
"broken" html.

Is there a way to only do the search and replace outside the tags and
comments.

It is further complicated by the fact that I would still like to do the
replacements within strings for example within meta tags!

Any ideas.

Henry











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




Re: [PHP] Re: Parsing HTML

2002-10-28 Thread Henry
Thanks Jay, I am still a newbie and I will read the manual, thankyou for the
help.

Having an OK day in the UK .   

Henry

"Jay Blanchard" <[EMAIL PROTECTED]> wrote in message
news:003f01c27e93$87bc1da0$8102a8c0@;000347D72515...
> [snip]
> What; nobody has anything to say about parsing HTML and doing search and
> replaces!! Is there another news group that might be better suited? I do
> want to do it PHP if I hadn't made that clear.
>
> Somebody, anybody, please help.
> [/snip]
>
> What? No one wants to help someone who didn't search the manual for
regular
> expressions? Things like eregi_replace()?
>
> RTFM, this is very basic.
>
> Having a bad day in Texas... :^[ *grrr*
>
> Jay
>
>



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




RE: [PHP] Re: Parsing HTML

2002-10-28 Thread Jay Blanchard
[snip]
What; nobody has anything to say about parsing HTML and doing search and
replaces!! Is there another news group that might be better suited? I do
want to do it PHP if I hadn't made that clear.

Somebody, anybody, please help.
[/snip]

What? No one wants to help someone who didn't search the manual for regular
expressions? Things like eregi_replace()?

RTFM, this is very basic.

Having a bad day in Texas... :^[ *grrr*

Jay



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




[PHP] Re: Parsing HTML

2002-10-28 Thread Henry
What; nobody has anything to say about parsing HTML and doing search and
replaces!! Is there another news group that might be better suited? I do
want to do it PHP if I hadn't made that clear.

Somebody, anybody, please help.

"Henry" <[EMAIL PROTECTED]> wrote in message
news:20021028103849.2175.qmail@;pb1.pair.com...
> Hi All,
>
> I would like to be able to do a serach and replace in a HTML document. For
a
> list of words;
>
> for example:
> hello become buongiorno
> yes becomes si
> size become grossezza
>
> The problem is that if I change the word "size" without considering html
> tags and html comments in the case of inline javascripts I'll end up with
> "broken" html.
>
> Is there a way to only do the search and replace outside the tags and
> comments.
>
> It is further complicated by the fact that I would still like to do the
> replacements within strings for example within meta tags!
>
> Any ideas.
>
> Henry
>
>



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




[PHP] Re: parsing conundrum

2002-10-26 Thread Monty
I'm not attempting to solve this puzzle, but, regarding the output from
print_r(), try this for nicely formatted output:

echo "";
print_r($myarray);
echo "";

Looks much better.

Monty


> From: [EMAIL PROTECTED] (Peter Harkins)
> Newsgroups: php.general
> Date: Sat, 26 Oct 2002 02:37:51 -0700
> To: [EMAIL PROTECTED]
> Subject: parsing conundrum
> 
> If you know what recursion is and like a challege, here's a puzzle
> to keep you up nights. If not, you'll probably just want to mutter to
> yourself "what a poor, unlucky bastard" and pass on by.
> 
> I'm parsing some data files into a PHP array and am stumped. I'm at
> a loss for how to do this without grinding through character by character.
> That would work, but my subconcious is nagging at me that there's got to be
> a more elegant way to do it that I'm just not seeing, so I'm going to
> describe the problem and ask for help before I start grinding.
> 
> The app I'm getting this from has 4 data types: int, string, array
> and mapping (associative array).
> 
> Ints and strings are pretty straightforward, but there's no way to
> tell 0 from null int or null string. This is an annoying limitation of the
> app that just has to be ignored and dealt with by whatever gets this data
> from us. This (among other reasons) make me glad PHP is weakly-typed.
> 
> Arrays are indexed from 0 and values can mix ints and strings
> freely.
> 
> To start, mappings are arrays indexed by ints or strings. Mappings
> aren't just arrays, though, they have a "width" (which is really a nested
> array that I'm pretty certain is an ugly historical artifact.) Width allows
> multiple values for one key and must be the same for all values in a
> mapping, though the values (both of keys and their values) don't have to be
> of the same type. Mappings can also mix ints and strings.
> 
> The tough part is that arrays and mappings can nest inside of each
> other and the only characters quoted in strings are \, " and \n. This means
> recursion must be used, but I just can't figure out a way to find the
> boundaries of each element. Anyone with a clean way to do this (probably
> with some kind of crazy regexp) will recieve my awe and gratitude.
> 
> Here's an example file[1]:
> 
> null_string 0
> some_string "Fourscore and seven years ago..."
> unset_int 0
> an_int 42
> negative_int -12
> null_array ({ })
> null_mapping ([ ])
> easy_array ({9,22,"test",})
> easy_mapping (["string":3,"foo":"bar",[12]:"I am not a crook!",])
> medium_array ({"a string, containing a comma and a \"",23,})
> medium_mapping (["str\"ing":3;5;7, 9:"Read my lips.";11;13;,])
> hard_array ({"comma, string",({3,4,5,}),({"'\"str'",4,({3,4,({ }),}),}),})
> hard_mapping ([17:"str";15,"foo":([ ]);17,"b'l\\a\nh":19;([21:23,]),"tour de
> force":({29,31});({([ ])}),])
> 
> You may notice the last one is pathological[2]. Yes, PHP will really
> let you use " and \n in array keys. The real data do sometimes get about
> this complex; consider this a compressed version. As a fun fact, I've
> learned vim's % command doesn't work when there's an odd number of double
> quotes between your parens/braces.
> 
> Calling print_r on the array this generates would return:
> 
> Array
> (
> [null_string] => 0
> [some_string] => "Fourscore and seven years ago..."
> [unset_int] => 0
> [an_int] => 42
> [negative_int] => -12
> [null_array] => Array
> (
> )
> 
> [null_mapping] => Array
> (
> )
> 
> [easy_array] => Array
> (
> [0] => 9
> [1] => 22
> [0] => test
> )
> 
> [easy_mapping] => Array
> (
> [string] => 3
> [foo] => "bar"
> [12] => "I am not a crook!"
> )
> 
> [medium_array] => Array
> (
> [0] => a string, containing a comma and a "
> [1] => 23
> )
> 
> [medium_mapping] => Array
> (
> [string] => Array
> (
> [0] => 3
> [1] => 5
> [2] => 7
> )
> 
> [9] => Array
> (
> [0] => Read my lips.
> [1] => 11
> [2] => 13
> )
> 
> )
> 
> [hard_array] => Array
> (
> [0] => comma, string
> [1] => Array
> (
> [0] => 3
> [1] => 4
> [2] => 5
> )
> 
> [2] => Array
> (
> [0] => '"str'
> [1] => 4
> [2] => Array
> (
> [0] => 3
> [1] => 4
> [2] => Array
> (
> )
> 
> )
> 
> )
> 
> )
> 
> [hard_mapping] => Array
> (
> [17] => Array
> (
> [0] => str
> [1] => 15
> )
> 
> [foo] => Array
> (
> [0] => Array
> (
> )
> 
> [1] => 17
> )
> 
> [b'l\a\nh] => Array
> (
> [0] => 19
> [1] => Array
> (
> [21] => 23
> )
> 
> )
> 
> [tour de force] => Array
> (
> [0] => Array
> (
> [29] => 31
> )
> 
> [1] => Array
> (
> [0] => Array
> (
> )
> )
> 
> )
> 
> )
> 
> )
> 
> The truly eagle-eyed will note that print_r doesn't really escape \n
> when outputting, which is ugly and should probably have a bug report filed
> on it. I've ignored this behavior of print_r to produce more readable
> output.
> 
> Anyone who gets the 'tour de force' can contact me for the 'victory
> lap' puzzle if it didn't occur to them while solving this one. It's equally
> frustrating.
> 
> [1] Brownie points to anyone who recognizes the app that outputs this data
> format. Yep, I'm doing web integration. Feel f

Re: [PHP] Re: parsing

2002-07-23 Thread Kevin Stone

Lee, yes you're right.  Using single quotes to denote a litteral string does
speed things up a bit.  My bench sped up by about .08 seconds over 10,000
echos.  That's about 5 pages worth of text.  Is .08 seconds worth worrying
about?  I'm gonna go out a limb here and say.. no.  :)
-Kevin


- Original Message -
From: "Lee Doolan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 23, 2002 1:40 PM
Subject: [PHP] Re: parsing


> >>>>> "Dave" == Dave At Sinewaves Net <[EMAIL PROTECTED]> writes:
>
> Dave> Okay, I want to know if anybody has a clue which is more
> Dave> efficient, processorwise/parsingwise:
>
> Dave> this: -- echo
> Dave>
"".$somevar."".$somevardesc."";
>
> Dave> or this: -- echo
> Dave>
"{$somevar}{$somevardesc}";
>
>
> Dave> I almost always use the first method (just seems more
> Dave> readable to me), but with all of the discussion popping up
> Dave> about curly brackets, i was wondering if it really makes a
> Dave> difference?  Any vets out there care to put in their $0.02?
>
> I bet that this would beat the pants off of both:
>
> echo ''. $somevar . '' . $somevardesc .
'';
>
>
> --
> When the birdcage is open,   | donate to causes I care about:
> the selfish bird flies away, |http://svcs.affero.net/rm.php?r=leed_25
> but the virtuous one stays.  |
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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




[PHP] Re: parsing

2002-07-23 Thread Lee Doolan

> "Dave" == Dave At Sinewaves Net <[EMAIL PROTECTED]> writes:

Dave> Okay, I want to know if anybody has a clue which is more
Dave> efficient, processorwise/parsingwise:

Dave> this: -- echo
Dave> "".$somevar."".$somevardesc."";

Dave> or this: -- echo
Dave> "{$somevar}{$somevardesc}";


Dave> I almost always use the first method (just seems more
Dave> readable to me), but with all of the discussion popping up
Dave> about curly brackets, i was wondering if it really makes a
Dave> difference?  Any vets out there care to put in their $0.02?

I bet that this would beat the pants off of both:

echo ''. $somevar . '' . $somevardesc . '';


-- 
When the birdcage is open,   | donate to causes I care about: 
the selfish bird flies away, |http://svcs.affero.net/rm.php?r=leed_25
but the virtuous one stays.  |

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




[PHP] Re: parsing

2002-07-23 Thread Peter

try
echo "$somevar$somevardesc";

which is probably better than the other two but don't quote me on that!
You can just include the variables because you have used " rather than ' (I
think it works for echo as well as print)

"Dave At Sinewaves.Net" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Okay,
>
> I want to know if anybody has a clue which is more efficient,
> processorwise/parsingwise:
>
> this:
> --
> echo
>
"".$somevar."".$somevardesc."";
>
> or this:
> --
> echo
"{$somevar}{$somevardesc}";
>
>
> I almost always use the first method (just seems more readable to me), but
> with all of the discussion popping up about curly brackets, i was
wondering
> if it really makes a difference?  Any vets out there care to put in their
> $0.02?
>
> Dave Tichy
> http://sinewaves.net/
>



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




[PHP] Re: Parsing CGI for PHP?

2002-07-09 Thread Richard Lynch

>Can this be done with apache 1.3 ?
>I want to have the output of my CGI-script to be parsed with PHP, or 
>rather, have the php within the  parsed, of course, since the 
>script outputs alot more than just php-code.
>
>Is it possible?


I don't think so.

Apache 1.x was designed to "hand off" the URL to one, and only one, CGI or Handler 
pre-processor.

Only with Apache 2.x can you "stack" handlers.  I dunno if Apache 2.x lets you 
mix&match CGI with Handlers, though.

Unless you can output to some kind of file somewhere, and send the user there with a 
Location: header, which is really ugly

-- 
Like Music?  http://l-i-e.com/artists.htm


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




RE: [PHP] Re: Parsing file's (SOLVED)

2002-06-02 Thread Scott

The next time I stare at something so long I can't think straight remind
me to take a walk and pull out Rasmus' book!  Page 121 array_chunk is my
friend!

Code is ugly, but I am smiling now!   Thank you everyone!

$policy = array_slice ($fields, 18, $lineCount);  
// I am taking the array from position 18 to the end
$chunks = array_chunk ($policy, 34);  
// Using array_chunk I break the array into pieces of 34
foreach ($chunks as $key => $value){
print_r($chunks);
sleep(5);
}
// The sleep is for me to watch it fly by the screen :)

Thanks again everyone.

-Scott



-Original Message-
From: Scott [mailto:[EMAIL PROTECTED]] 
Sent: Sunday, June 02, 2002 4:57 PM
To: 'Mark Heintz PHP Mailing Lists'
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP] Re: Parsing file's

Ok, this did not work, but I have a new idea.  From the top

1)Read in the csv file, take the first 18 records and insert them into a
temp db.Ie:  $output = array_slice ($fields, 0, 17);

2)Then do a count on the line to see how many records are after 17 and
somehow loop through them 34 at a time.  

It is easy if there is only one set, but I am not sure how to take the
remaining elements in the array and break them out 34 at a time until I
reach the end of the line.  

Help, my head hurts and I have a habit of over thinking :)

-Scott




-Original Message-
From: Mark Heintz PHP Mailing Lists [mailto:[EMAIL PROTECTED]] 
Sent: Friday, May 31, 2002 4:43 PM
To: Scott
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Re: Parsing file's

You may have been heading in the right direction originally with
array_slice...  This is off the top of my head, I don't guaruntee it
will
work...

$start = 34;
$interval = 15;
$max = 303;
// hop across orig. array 15 columns at a time
for($offset = $start;
$offset < $max && isset($array[$offset]);
$offset += $interval){
  // slice off $interval many columns starting at $offset
  $sub_array = array_slice($array, $i, $interval);
  // handle your $interval many key-value pairs
  foreach ($sub_array as $key => $value){
$policyWriter = "$quoteKey|$key|$value";
// ...
  }
}


mh.




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


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




RE: [PHP] Re: Parsing file's

2002-06-02 Thread Scott

Ok, this did not work, but I have a new idea.  From the top

1)Read in the csv file, take the first 18 records and insert them into a
temp db.Ie:  $output = array_slice ($fields, 0, 17);

2)Then do a count on the line to see how many records are after 17 and
somehow loop through them 34 at a time.  

It is easy if there is only one set, but I am not sure how to take the
remaining elements in the array and break them out 34 at a time until I
reach the end of the line.  

Help, my head hurts and I have a habit of over thinking :)

-Scott




-Original Message-
From: Mark Heintz PHP Mailing Lists [mailto:[EMAIL PROTECTED]] 
Sent: Friday, May 31, 2002 4:43 PM
To: Scott
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Re: Parsing file's

You may have been heading in the right direction originally with
array_slice...  This is off the top of my head, I don't guaruntee it
will
work...

$start = 34;
$interval = 15;
$max = 303;
// hop across orig. array 15 columns at a time
for($offset = $start;
$offset < $max && isset($array[$offset]);
$offset += $interval){
  // slice off $interval many columns starting at $offset
  $sub_array = array_slice($array, $i, $interval);
  // handle your $interval many key-value pairs
  foreach ($sub_array as $key => $value){
$policyWriter = "$quoteKey|$key|$value";
// ...
  }
}


mh.




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




RE: [PHP] Re: Parsing file's

2002-05-31 Thread Scott

Mark-

Trying it now, I think I understand what you doing with the code below.
I'll let you know.

Thank you!

-Scott

-Original Message-
From: Mark Heintz PHP Mailing Lists [mailto:[EMAIL PROTECTED]] 
Sent: Friday, May 31, 2002 4:43 PM
To: Scott
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Re: Parsing file's

You may have been heading in the right direction originally with
array_slice...  This is off the top of my head, I don't guaruntee it
will
work...

$start = 34;
$interval = 15;
$max = 303;
// hop across orig. array 15 columns at a time
for($offset = $start;
$offset < $max && isset($array[$offset]);
$offset += $interval){
  // slice off $interval many columns starting at $offset
  $sub_array = array_slice($array, $i, $interval);
  // handle your $interval many key-value pairs
  foreach ($sub_array as $key => $value){
$policyWriter = "$quoteKey|$key|$value";
// ...
  }
}


mh.


On Fri, 31 May 2002, Scott wrote:

> That's what I mean by starring at this too much :)  I tried writting
to a
> seperate file, but is there a way to take an array and split it every
so
> many records within another loop?
>
> Let's say the first row contains the first 18 columns which I already
> parsed, I then want to grab the next 5 15 columns, but need to
seperate
> them in groups of 15.  I tried this:
>
> foreach ($output as $key => $value){
>   $policyWriter = "$quoteKey|$key|$value";
>   fwrite ($policyFile,"$policyWriter\r\n");
> }
>
> Which will take and print the rest of the row, but I needo split the
> columns into groups of 15.
>
> -Scott
>
>
>
>
>
> On Fri, 31 May 2002, Michael Davey wrote:
>
> > You should normalise your data - have a field in the second csv that
links
> > to the first csv and then you can have as many rows as you want
associated
> > with the record in the first file.
> >
> > Mikey
> >
> > "Scott" <[EMAIL PROTECTED]> wrote in message
> > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > > I have a csv file that I am parsing, formatting and then writting
to a new
> > > file.  I am currently using an array, but I have some lines that
might
> > > contain more data than others.  I know for sure that columns 0-33
will
> > > always be there, but the customer has the option to add another
set of
> > > columns to the row if needed.  I do know that the addition's will
always
> > > be 18 columns and I do know that they can add up to 15 set's of
18.  So,
> > > the row length could be 0-33 or 0-51 if they add one additional
set or 303
> > > columns if they go up to 15.
> > >
> > > The tricky part is I have to format each column for the new file
that is
> > > created, I do this using sprintf.  I have so far tried to use
array_slice
> > >  for the first 18 columns, then I do another array_slice starting
at 18
> > > and using the column count to get the last column in the row.
Here is the
> > > code:
> > >
> > > array_slice($fields, 18,$lineCount);
> > > foreach ($fields as $key => $value){
> > > print "$key|$value\r\n";
> > > }
> > >
> > > The format of the new file will be this:
> > > 01-Customer information
> > > 02-Other information
> > > 03a Required Info (that can repeat up to 15 times per line)
> > > 03b ""
> > > 04b ""
> > > 04-Close Customer Record
> > >
> > > Repeat cycle for each row.  The inner loop happens between the 02
and 04
> > > records.  Remember, I need to format each individual column, they
are
> > > different format options.
> > >
> > > If you have some thoughts, I would be all ears as I have been
starring at
> > > this too long and too hard.
> > >
> > > Thanks,
> > >
> > > -Scott




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




Re: [PHP] Re: Parsing file's

2002-05-31 Thread Mark Heintz PHP Mailing Lists

You may have been heading in the right direction originally with
array_slice...  This is off the top of my head, I don't guaruntee it will
work...

$start = 34;
$interval = 15;
$max = 303;
// hop across orig. array 15 columns at a time
for($offset = $start;
$offset < $max && isset($array[$offset]);
$offset += $interval){
  // slice off $interval many columns starting at $offset
  $sub_array = array_slice($array, $i, $interval);
  // handle your $interval many key-value pairs
  foreach ($sub_array as $key => $value){
$policyWriter = "$quoteKey|$key|$value";
// ...
  }
}


mh.


On Fri, 31 May 2002, Scott wrote:

> That's what I mean by starring at this too much :)  I tried writting to a
> seperate file, but is there a way to take an array and split it every so
> many records within another loop?
>
> Let's say the first row contains the first 18 columns which I already
> parsed, I then want to grab the next 5 15 columns, but need to seperate
> them in groups of 15.  I tried this:
>
> foreach ($output as $key => $value){
>   $policyWriter = "$quoteKey|$key|$value";
>   fwrite ($policyFile,"$policyWriter\r\n");
> }
>
> Which will take and print the rest of the row, but I needo split the
> columns into groups of 15.
>
> -Scott
>
>
>
>
>
> On Fri, 31 May 2002, Michael Davey wrote:
>
> > You should normalise your data - have a field in the second csv that links
> > to the first csv and then you can have as many rows as you want associated
> > with the record in the first file.
> >
> > Mikey
> >
> > "Scott" <[EMAIL PROTECTED]> wrote in message
> > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > > I have a csv file that I am parsing, formatting and then writting to a new
> > > file.  I am currently using an array, but I have some lines that might
> > > contain more data than others.  I know for sure that columns 0-33 will
> > > always be there, but the customer has the option to add another set of
> > > columns to the row if needed.  I do know that the addition's will always
> > > be 18 columns and I do know that they can add up to 15 set's of 18.  So,
> > > the row length could be 0-33 or 0-51 if they add one additional set or 303
> > > columns if they go up to 15.
> > >
> > > The tricky part is I have to format each column for the new file that is
> > > created, I do this using sprintf.  I have so far tried to use array_slice
> > >  for the first 18 columns, then I do another array_slice starting at 18
> > > and using the column count to get the last column in the row.  Here is the
> > > code:
> > >
> > > array_slice($fields, 18,$lineCount);
> > > foreach ($fields as $key => $value){
> > > print "$key|$value\r\n";
> > > }
> > >
> > > The format of the new file will be this:
> > > 01-Customer information
> > > 02-Other information
> > > 03a Required Info (that can repeat up to 15 times per line)
> > > 03b ""
> > > 04b ""
> > > 04-Close Customer Record
> > >
> > > Repeat cycle for each row.  The inner loop happens between the 02 and 04
> > > records.  Remember, I need to format each individual column, they are
> > > different format options.
> > >
> > > If you have some thoughts, I would be all ears as I have been starring at
> > > this too long and too hard.
> > >
> > > Thanks,
> > >
> > > -Scott




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




Re: [PHP] Re: Parsing file's

2002-05-31 Thread Scott

That's what I mean by starring at this too much :)  I tried writting to a 
seperate file, but is there a way to take an array and split it every so 
many records within another loop?  

Let's say the first row contains the first 18 columns which I already 
parsed, I then want to grab the next 5 15 columns, but need to seperate 
them in groups of 15.  I tried this:

foreach ($output as $key => $value){
  $policyWriter = "$quoteKey|$key|$value";
  fwrite ($policyFile,"$policyWriter\r\n");
}

Which will take and print the rest of the row, but I needo split the 
columns into groups of 15.

-Scott





On Fri, 31 May 2002, Michael Davey wrote:

> You should normalise your data - have a field in the second csv that links
> to the first csv and then you can have as many rows as you want associated
> with the record in the first file.
> 
> Mikey
> 
> "Scott" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > I have a csv file that I am parsing, formatting and then writting to a new
> > file.  I am currently using an array, but I have some lines that might
> > contain more data than others.  I know for sure that columns 0-33 will
> > always be there, but the customer has the option to add another set of
> > columns to the row if needed.  I do know that the addition's will always
> > be 18 columns and I do know that they can add up to 15 set's of 18.  So,
> > the row length could be 0-33 or 0-51 if they add one additional set or 303
> > columns if they go up to 15.
> >
> > The tricky part is I have to format each column for the new file that is
> > created, I do this using sprintf.  I have so far tried to use array_slice
> >  for the first 18 columns, then I do another array_slice starting at 18
> > and using the column count to get the last column in the row.  Here is the
> > code:
> >
> > array_slice($fields, 18,$lineCount);
> > foreach ($fields as $key => $value){
> > print "$key|$value\r\n";
> > }
> >
> > The format of the new file will be this:
> > 01-Customer information
> > 02-Other information
> > 03a Required Info (that can repeat up to 15 times per line)
> > 03b ""
> > 04b ""
> > 04-Close Customer Record
> >
> > Repeat cycle for each row.  The inner loop happens between the 02 and 04
> > records.  Remember, I need to format each individual column, they are
> > different format options.
> >
> > If you have some thoughts, I would be all ears as I have been starring at
> > this too long and too hard.
> >
> > Thanks,
> >
> > -Scott
> >
> >
> 
> 
> 
> 

-- 

[EMAIL PROTECTED]

Now Playing: Moby - We Are All Made Of Stars
generated by ProWeb 1.0 Beta
Uptime 168 days
c2002 Exton Communications



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




[PHP] Re: Parsing file's

2002-05-31 Thread Michael Davey

You should normalise your data - have a field in the second csv that links
to the first csv and then you can have as many rows as you want associated
with the record in the first file.

Mikey

"Scott" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I have a csv file that I am parsing, formatting and then writting to a new
> file.  I am currently using an array, but I have some lines that might
> contain more data than others.  I know for sure that columns 0-33 will
> always be there, but the customer has the option to add another set of
> columns to the row if needed.  I do know that the addition's will always
> be 18 columns and I do know that they can add up to 15 set's of 18.  So,
> the row length could be 0-33 or 0-51 if they add one additional set or 303
> columns if they go up to 15.
>
> The tricky part is I have to format each column for the new file that is
> created, I do this using sprintf.  I have so far tried to use array_slice
>  for the first 18 columns, then I do another array_slice starting at 18
> and using the column count to get the last column in the row.  Here is the
> code:
>
> array_slice($fields, 18,$lineCount);
> foreach ($fields as $key => $value){
> print "$key|$value\r\n";
> }
>
> The format of the new file will be this:
> 01-Customer information
> 02-Other information
> 03a Required Info (that can repeat up to 15 times per line)
> 03b ""
> 04b ""
> 04-Close Customer Record
>
> Repeat cycle for each row.  The inner loop happens between the 02 and 04
> records.  Remember, I need to format each individual column, they are
> different format options.
>
> If you have some thoughts, I would be all ears as I have been starring at
> this too long and too hard.
>
> Thanks,
>
> -Scott
>
>



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




[PHP] Re: parsing CSV, updating MySQL table

2002-05-18 Thread Jason Morehouse

You could use mysql import / outfile:

http://www.mysql.com/doc/S/E/SELECT.html

See the section " * The SELECT ... INTO OUTFILE".

Hope that helps.
-J

On Sat, 18 May 2002 20:41:39 +1200, Justin French wrote:

> Hi,
> 
> I have a client with an Excel file of products / prices / etc.  For
> arguments sake, let's keep it simple:
> 
> id,title,description
> 
> if they were to export this as a CSV, then it could be used to update a
> mysql table (for existing ID's), and to insert any new ID's.
> 
> 
> So, I guess what I'm after is a group of functions which parse a CSV
> file, and update a MySQL table to match... rather than messing around in
> a web based GUI, the client could just upload a new CSV every couple of
> days.
> 
> 
> I've checked out fgetcsv() etc, and I *think* i've got a picture of how
> the code would look, but before I start, I figure a set of functions
> probably already exists out there to do this... so why reinvent the
> wheel
> 
> If anyone can point me to a URL, class, function, article, etc, I'd be
> pretty happy :)
> 
> 
> Justin French
 

-- 
 Jason Morehouse ([EMAIL PROTECTED])
 Netconcepts LTD, Auckland, New Zealand
 * Linux: because rebooting is for adding hardware.

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




[PHP] Re: parsing HTML text

2002-05-07 Thread Austin Marshall

Lee Doolan wrote:
> 
> I have written form screen which has as one of it's elements a
>  box in which a user can input some text --like a simple
> bio-- which will appear on another screen.  I'd like to edit check
> this text. It would be a good idea to make sure that it has, among other
> things, no  elements, say, or to make sure that if a 
> tag occurs, that a matching  tag is present.
> 
> Is anyone aware of a  class or a package which I can use to parse this
> text and do this kind of validation?
> 
> tia
> -lee
> 

strip_tags() is your friend, http://www.php.net/strip_tags


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




  1   2   >