php-general Digest 14 Oct 2009 19:52:55 -0000 Issue 6390

Topics (messages 298887 through 298895):

SimpleXML var_dump() weirdness
        298887 by: Mattias Thorslund

Re: Signing (hand-written signature) pdf document
        298888 by: Ashley Sheridan

regex for multiple line breakes
        298889 by: Merlin Morgenstern
        298890 by: Fernando Castillo Aparicio
        298891 by: Merlin Morgenstern
        298892 by: Ashley Sheridan
        298893 by: Fernando Castillo Aparicio
        298894 by: Merlin Morgenstern

Re: Need unrounded precision
        298895 by: Philip Thompson

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Hi,

It seems that var_dump() of a SimpleXMLElement does not show an attribute of elements that contain text content?

I hope my examples might show what I mean:

$xml = '<root rootattr="root value"><inner attr="value"/></root>';
$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple->asXML();

This results in:

object(SimpleXMLElement)#1 (2) {
 ["@attributes"]=>
 array(1) {
   ["rootattr"]=>
   string(10) "root value"
 }
 ["inner"]=>
 object(SimpleXMLElement)#2 (1) {
   ["@attributes"]=>
   array(1) {
     ["attr"]=>
     string(5) "value"
   }
 }
}
<?xml version="1.0"?>
<root rootattr="root value"><inner attr="value"/></root>

...and that's fine, though it would have been nice to also know that the root element is called "root".

The second example manifests the weirdness:

$xml = '<root rootattr="root value"><inner attr="value">text</inner></root>';
$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple->asXML();

Outputs:

object(SimpleXMLElement)#1 (2) {
 ["@attributes"]=>
 array(1) {
   ["rootattr"]=>
   string(10) "root value"
 }
 ["inner"]=>
 string(4) "text"
}
<?xml version="1.0"?>
<root rootattr="root value"><inner attr="value">text</inner></root>

Notice that the attribute "attr" of the element "inner" is not displayed.

In the third case, I replace the content of the "inner" element with another element:

$xml = '<root rootattr="root value"><inner attr="value"><deep/></inner></root>';
$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple->asXML();

Outputs:

object(SimpleXMLElement)#1 (2) {
 ["@attributes"]=>
 array(1) {
   ["rootattr"]=>
   string(10) "root value"
 }
 ["inner"]=>
 object(SimpleXMLElement)#2 (2) {
   ["@attributes"]=>
   array(1) {
     ["attr"]=>
     string(5) "value"
   }
   ["deep"]=>
   object(SimpleXMLElement)#3 (0) {
   }
 }
}
<?xml version="1.0"?>
<root rootattr="root value"><inner attr="value"><deep/></inner></root>

The "invisible" attributes are still accessible with xpath(), etc (the asXML() dump shows that it is still present, but just not visible. This might be a bug? Or am I just not understanding something?

Cheers,

Mattias
PHP 5.2.6

--- End Message ---
--- Begin Message ---
On Tue, 2009-10-13 at 20:07 -0700, nashrul wrote:

> Hi...
> I'm thinking about a document management system that can put user signature
> on the created digital document. Here's the app-flow I can imagine ...
> My php application creates a pdf document.
> The pdf document is displayed to user.
> Using the digital pen, the user will put his/her signature on this document.
> or Using the touch screen, the user will put his/her signature.
> The pdf document with the user signature is saved to the db.
> Has anyone done this before ??
> Thanks
> -- 
> View this message in context: 
> http://www.nabble.com/Signing-%28hand-written-signature%29-pdf-document-tp25884660p25884660.html
> Sent from the PHP - General mailing list archive at Nabble.com.
> 
> 


A signature in a document is just an image. I've seen plenty of Flash
apps which allow a user to draw something which is then saved as an
image. You could then use this image file and either re-create the PDF
document (easiest) or attempt to edit it and add the image in.

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



--- End Message ---
--- Begin Message ---
Hi there,

I am trying to remove multiple linebreakes from a textarea input. Spammers tend to insert multiple line breakes. The problem is, that I want to allow 2 line breaks so basic formating should be allowed.

I am doing this by regex:
$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

I would need a regex that allows \r\n\r\n, but not more than this.

Thank you for any help,

Merlin

--- End Message ---
--- Begin Message ---
You are replacing 1 or more matchs of a new line. To match 2 or more you can 
use "{2,}". It's a range, first number means min matches, second max matches. 
Omitting last number means no max limit.

$data[txt] = preg_replace('`[\r\n]{2,}`',"\n",$data[txt]);



________________________________
De: Merlin Morgenstern <merli...@fastmail.fm>
Para: php-gene...@lists.php.net
Enviado: mié,14 octubre, 2009 12:17
Asunto: [PHP] regex for multiple line breakes

Hi there,

I am trying to remove multiple linebreakes from a textarea input. Spammers tend 
to insert multiple line breakes. The problem is, that I want to allow 2 line 
breaks so basic formating should be allowed.

I am doing this by regex:
$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

I would need a regex that allows \r\n\r\n, but not more than this.

Thank you for any help,

Merlin

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


      

--- End Message ---
--- Begin Message ---
That sounds very logical but does not work unfortunatelly.
The result is the same. It removes all linebreakes but one.
I would like to pass this one:

---------
first line

second
third
---------

But not this one:
---------
third




forth
--------



Fernando Castillo Aparicio schrieb:
You are replacing 1 or more matchs of a new line. To match 2 or more you can use 
"{2,}". It's a range, first number means min matches, second max matches. 
Omitting last number means no max limit.

$data[txt] = preg_replace('`[\r\n]{2,}`',"\n",$data[txt]);



________________________________
De: Merlin Morgenstern <merli...@fastmail.fm>
Para: php-gene...@lists.php.net
Enviado: mié,14 octubre, 2009 12:17
Asunto: [PHP] regex for multiple line breakes

Hi there,

I am trying to remove multiple linebreakes from a textarea input. Spammers tend 
to insert multiple line breakes. The problem is, that I want to allow 2 line 
breaks so basic formating should be allowed.

I am doing this by regex:
$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

I would need a regex that allows \r\n\r\n, but not more than this.

Thank you for any help,

Merlin

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



--- End Message ---
--- Begin Message ---
On Wed, 2009-10-14 at 12:42 +0200, Merlin Morgenstern wrote:

> That sounds very logical but does not work unfortunatelly.
> The result is the same. It removes all linebreakes but one.
> I would like to pass this one:
> 
> ---------
> first line
> 
> second
> third
> ---------
> 
> But not this one:
> ---------
> third
> 
> 
> 
> 
> forth
> --------
> 
> 
> 
> Fernando Castillo Aparicio schrieb:
> > You are replacing 1 or more matchs of a new line. To match 2 or more you 
> > can use "{2,}". It's a range, first number means min matches, second max 
> > matches. Omitting last number means no max limit.
> > 
> > $data[txt] = preg_replace('`[\r\n]{2,}`',"\n",$data[txt]);
> > 
> > 
> > 
> > ________________________________
> > De: Merlin Morgenstern <merli...@fastmail.fm>
> > Para: php-gene...@lists.php.net
> > Enviado: mié,14 octubre, 2009 12:17
> > Asunto: [PHP] regex for multiple line breakes
> > 
> > Hi there,
> > 
> > I am trying to remove multiple linebreakes from a textarea input. Spammers 
> > tend to insert multiple line breakes. The problem is, that I want to allow 
> > 2 line breaks so basic formating should be allowed.
> > 
> > I am doing this by regex:
> > $data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);
> > 
> > I would need a regex that allows \r\n\r\n, but not more than this.
> > 
> > Thank you for any help,
> > 
> > Merlin
> > 
> > -- PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> > 
> >       
> 


You still have an issue with your regex:

$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

Even if you replace the + with a {2,} you are asking it to match any one
of the characters in the square brackets twice or more and replace it
with a single \n. If your line breaks actually do consist of the \r\n
pattern, then the {2,} will match those two characters, not two sets of
those characters. You might be better off replacing all \r characters
with an empty string, and then matching against the \n character only.

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



--- End Message ---
--- Begin Message ---
Right. I saw it later. To be completely multiplatform I'd use a grouping: 
(\n|\r|\r\n){2,}. If I'm not wrong, these are all the actual formats for a new 
line.

If we replace \r with a newline we could fail if the text comes from a MAC OS.




________________________________
De: Ashley Sheridan <a...@ashleysheridan.co.uk>
Para: Merlin Morgenstern <merli...@fastmail.fm>
CC: php-gene...@lists.php.net
Enviado: mié,14 octubre, 2009 12:44
Asunto: Re: [PHP] regex for multiple line breakes

On Wed, 2009-10-14 at 12:42 +0200, Merlin Morgenstern wrote:

> That sounds very logical but does not work unfortunatelly.
> The result is the same. It removes all linebreakes but one.
> I would like to pass this one:
> 
> ---------
> first line
> 
> second
> third
> ---------
> 
> But not this one:
> ---------
> third
> 
> 
> 
> 
> forth
> --------
> 
> 
> 
> Fernando Castillo Aparicio schrieb:
> > You are replacing 1 or more matchs of a new line. To match 2 or more you 
> > can use "{2,}". It's a range, first number means min matches, second max 
> > matches. Omitting last number means no max limit.
> > 
> > $data[txt] = preg_replace('`[\r\n]{2,}`',"\n",$data[txt]);
> > 
> > 
> > 
> > ________________________________
> > De: Merlin Morgenstern <merli...@fastmail.fm>
> > Para: php-gene...@lists.php.net
> > Enviado: mié,14 octubre, 2009 12:17
> > Asunto: [PHP] regex for multiple line breakes
> > 
> > Hi there,
> > 
> > I am trying to remove multiple linebreakes from a textarea input. Spammers 
> > tend to insert multiple line breakes. The problem is, that I want to allow 
> > 2 line breaks so basic formating should be allowed.
> > 
> > I am doing this by regex:
> > $data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);
> > 
> > I would need a regex that allows \r\n\r\n, but not more than this.
> > 
> > Thank you for any help,
> > 
> > Merlin
> > 
> > -- PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> > 
> >      
> 


You still have an issue with your regex:

$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

Even if you replace the + with a {2,} you are asking it to match any one
of the characters in the square brackets twice or more and replace it
with a single \n. If your line breaks actually do consist of the \r\n
pattern, then the {2,} will match those two characters, not two sets of
those characters. You might be better off replacing all \r characters
with an empty string, and then matching against the \n character only.

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


      

--- End Message ---
--- Begin Message ---


Ashley Sheridan schrieb:
On Wed, 2009-10-14 at 12:42 +0200, Merlin Morgenstern wrote:

That sounds very logical but does not work unfortunatelly.
The result is the same. It removes all linebreakes but one.
I would like to pass this one:

---------
first line

second
third
---------

But not this one:
---------
third




forth
--------



Fernando Castillo Aparicio schrieb:
You are replacing 1 or more matchs of a new line. To match 2 or more you can use 
"{2,}". It's a range, first number means min matches, second max matches. 
Omitting last number means no max limit.

$data[txt] = preg_replace('`[\r\n]{2,}`',"\n",$data[txt]);



________________________________
De: Merlin Morgenstern <merli...@fastmail.fm>
Para: php-gene...@lists.php.net
Enviado: mié,14 octubre, 2009 12:17
Asunto: [PHP] regex for multiple line breakes

Hi there,

I am trying to remove multiple linebreakes from a textarea input. Spammers tend 
to insert multiple line breakes. The problem is, that I want to allow 2 line 
breaks so basic formating should be allowed.

I am doing this by regex:
$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

I would need a regex that allows \r\n\r\n, but not more than this.

Thank you for any help,

Merlin

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




You still have an issue with your regex:

$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

Even if you replace the + with a {2,} you are asking it to match any one
of the characters in the square brackets twice or more and replace it
with a single \n. If your line breaks actually do consist of the \r\n
pattern, then the {2,} will match those two characters, not two sets of
those characters. You might be better off replacing all \r characters
with an empty string, and then matching against the \n character only.

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



Thank you. That worked!
$data[txt] = preg_replace('`[\n]{3,}`',"\n",str_replace("\r", "",$data[txt]));
--- End Message ---
--- Begin Message ---
On Oct 12, 2009, at 2:37 PM, Andrea Giammarchi wrote:

bitwise right shift is probably the fastest cast to int so far ... still in many languages, intval is a function call

being a cast in both cases (int) is good as well ... bitwise, casting, works with strings, arrays, boolean, whatever as well.

I don't think there is any difference in php, except when the integer is "too big" ... but this was not the case, we had to deal with 1 to 10 :-)

Regards

From: jbo...@mindsites.com
To: an_...@hotmail.com
CC: php-gene...@lists.php.net
Date: Mon, 12 Oct 2009 11:33:10 -0500
Subject: RE: [PHP] Need unrounded precision

Hmmm... Didn't think about this, but % only works with int values

it was just future prof precaution since this statement is false for many other languages.
In few words I am not sure PHP6 does the same ... never mind so far

Good to know. In that case, I would probably just use intval() instead of >> since it's clearer and bitwise shifts aren't necessarily integer only either.

Jaime

I like the bitwise shifting, but here's another potential (albeit probably slower) solution.

$a = 28.56018;
list (,$dec) = explode ('.', $a);
$b = $dec{0};

Cheers,
~Philip

--- End Message ---

Reply via email to