php-general Digest 7 Oct 2011 03:38:33 -0000 Issue 7508
Topics (messages 315153 through 315159):
Issues with simplexml_load_string()
315153 by: Christoph Boget
315155 by: Christoph Boget
Re: Namespaced code with SabreDAV
315154 by: Tommy Pham
Problem with code...
315156 by: Jason Pruim
315157 by: George Langley
315158 by: Jason Pruim
315159 by: Tommy Pham
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
It seems like when dealing with nodes which have CDATA, I cannot get
access to both the attributes of that node and the CDATA of that node
with the same simplexml_load_string() call. Consider the following:
$previewString =
'<root><message><![CDATA[lkjlkjklj]]></message><buttons><button
name="Add Me"><![CDATA[This is my free form
text]]></button></buttons></root>';
When passing LIBXML_NOCDATA:
echo '<pre>' . print_r( json_decode( json_encode(
(array)simplexml_load_string( $previewString, 'SimpleXMLElement',
LIBXML_NOCDATA | LIBXML_NOBLANKS )), 1 ), TRUE ) . '</pre>';
yields the following output :
Array
(
[message] => lkjlkjklj
[buttons] => Array
(
[button] => This is my free form text
)
)
So I get the CDATA but I don't get the "name" attribute for the button.
When not using LIBXML_NOCDATA:
echo '<pre>' . print_r( json_decode( json_encode(
(array)simplexml_load_string( $previewString, 'SimpleXMLElement',
LIBXML_NOBLANKS )), 1 ), TRUE ) . '</pre>';
yields the following output :
Array
(
[message] => Array
(
)
[buttons] => Array
(
[button] => Array
(
[@attributes] => Array
(
[name] => Add Me
)
)
)
)
I get the attributes but not the CDATA. Looking at the doc page for
simplexml_load_string()
(http://us.php.net/manual/en/function.simplexml-load-string.php and
http://us.php.net/manual/en/libxml.constants.php), I don't see a way
to get access to both. Am I missing something? Or is this really not
possible?
thnx,
Christoph
--- End Message ---
--- Begin Message ---
It seems like when dealing with nodes which have CDATA, I cannot get
access to both the attributes of that node and the CDATA of that node
with the same simplexml_load_string() call. Consider the following:
$previewString =
'<root><message><![CDATA[lkjlkjklj]]></message><buttons><button
name="Add Me"><![CDATA[This is my free form
text]]></button></buttons></root>';
When passing LIBXML_NOCDATA:
echo '<pre>' . print_r( json_decode( json_encode(
(array)simplexml_load_string( $previewString, 'SimpleXMLElement',
LIBXML_NOCDATA | LIBXML_NOBLANKS )), 1 ), TRUE ) . '</pre>';
yields the following output :
Array
(
[message] => lkjlkjklj
[buttons] => Array
(
[button] => This is my free form text
)
)
So I get the CDATA but I don't get the "name" attribute for the button.
When not using LIBXML_NOCDATA:
echo '<pre>' . print_r( json_decode(
json_encode((array)simplexml_load_string( $previewString,
'SimpleXMLElement', LIBXML_NOBLANKS )), 1 ), TRUE ) . '</pre>';
yields the following output :
Array
(
[message] => Array
(
)
[buttons] => Array
(
[button] => Array
(
[@attributes] => Array
(
[name] => Add Me
)
)
)
)
I get the attributes but not the CDATA. Looking at the doc page for
simplexml_load_string()
(http://us.php.net/manual/en/function.simplexml-load-string.php and
http://us.php.net/manual/en/libxml.constants.php), I don't see a way
to get access to both. Am I missing something? Or is this really not
possible?
thnx,
Christoph
--- End Message ---
--- Begin Message ---
On Thu, Oct 6, 2011 at 7:37 AM, Andrew Mason <[email protected]> wrote:
> Hello all,
> I am trying to use the wonderful SabreDAV library to create a webdav
> share. I have a demo up and running however the framework / class i'm
> using is namespaced, and SabreDAV unfortunately does not have a 5.3
> style namespace declaration.
>
> I have an spl_autoload function registered in my base controller and
> so long as I prefix the classname with a \ it all works:
>
>
> $rootDirectory = new \Sabre_DAV_FS_Directory($rootDir);
>
> // The server object is responsible for making sense out of the WebDAV
> protocol
> $server = new \Sabre_DAV_Server($rootDirectory);
>
>
> However, SabreDAV it's self has a large amount of other PHP classes
> which it calls which obviously aren't prefixed with '\'
>
> Is there a way i can tell PHP any class name that get's instanciated
> with 'Sabre_' should resolve to '\Sabre' ?
>
> Many thanks
> Andrew
>
>
If my memory serves regarding PHP's namespace, you could build something
like this
$file = APP_DIR.'\'.$class;
if( file_exists( $file ) ) require_once $file;
into your autoloader. You may have to adjust '/' to/from '\\' depending on
your platform or you can use the constant DIRECTORY_SEPARATOR in the full
path to the class. Then you don't need add \ before your class to
instantiate. I don't know how the SabreDAV framework looks like but you may
want to look at how Zend framework loads their class as to give you some
idea what you may need to do in your autoload to circumvent SabreDAV being
not 5.3 namespace declaration. You may also want to take a look at
CodeIgniter's autoloading mechanism.
Regards,
Tommy
--- End Message ---
--- Begin Message ---
Hi everyone,
Have a question about this block of code....
<?PHP
//SETUP VARIABLES
$mailTo = "[email protected]";
$mailFrom = "[email protected]";
//These 2 can be changed IF you know what you are doing and why!
$returnPath = $mailFrom;
$replyTo = $mailFrom;
$mailSubject = "New Convention registration!";
$message = "";
//DO NOT CHANGE UNDER PENALITY OF BEING SLAPPED WITH A WET NOODLE!!!
$headers = "From: ".$mailFrom."\n";
$headers .= "Return-Path: ".$returnPath."\n";
$headers .= "Reply-To: ".$replyTo."\n";
function send_email($mailTo, $mailSubject, $mailMessage, $headers) {
if(mail( $mailTo, $mailSubject, $mailMessage, $headers )) {
$message = "Thank you for registering!";
}else {
echo "There was an issue with your registration.. Please try again
later";
}
}//Close Function
if(!empty($errorCount)) {
}else {
//Build Email message
$mailmessage = "Full Name: " . $_POST['firstname'] . " " .
$_POST['lastname'] . "\n\n";
$mailmessage .= "Address: " . $_POST['address'] . "\n\n";
$mailmessage .= "City, State, Zip: " . $_POST['city'] . " " .
$_POST['state'] . " " . $_POST['zip'] . "\n\n";
$mailmessage .= "Phone: " . $_POST['phone'] . "\n\n";
$mailmessage .= "Email address: " . $_POST['email'] . "\n\n";
if($_POST['affiliation'] == "NFBOther") {
$mailmessage .= "Chapter Affiliation: " . $_POST['other'] .
"\n\n";
}else{
$mailmessage .= "Chapter Affiliation: " . $_POST['affiliation']
. "\n\n";
}
if($_POST['person'] =="Other"){
$mailmessage .= "Who will pick up the ticket? " .
$_POST['Pfirstname'] . " " . $_POST['Llastname'] . "\n\n";
}else{
$mailmessage .= "Who will pick up the ticket? I will pick it up
my self! \n\n";
}
$mailmessage .= "Payment Method: " . $_POST['paymentMethod'];
send_email($mailTo, $mailSubject, $mailmessage, $headers);
}
?>
Sometimes... It is dropping the last $mailmessage line... The payment method in
the actual email it sends...
Anyone have any ideas? I'm stumped....
Jason Pruim
[email protected]
--- End Message ---
--- Begin Message ---
On 2011-10-06, at 6:28 PM, Jason Pruim wrote:
>
> <?PHP
>
> //SETUP VARIABLES
>
> $mailTo = "[email protected]";
> $mailFrom = "[email protected]";
> //These 2 can be changed IF you know what you are doing and why!
> $returnPath = $mailFrom;
> $replyTo = $mailFrom;
> $mailSubject = "New Convention registration!";
>
> $message = "";
>
> //DO NOT CHANGE UNDER PENALITY OF BEING SLAPPED WITH A WET NOODLE!!!
>
> $headers = "From: ".$mailFrom."\n";
> $headers .= "Return-Path: ".$returnPath."\n";
> $headers .= "Reply-To: ".$replyTo."\n";
>
> function send_email($mailTo, $mailSubject, $mailMessage, $headers) {
>
>
> if(mail( $mailTo, $mailSubject, $mailMessage, $headers )) {
>
> $message = "Thank you for registering!";
>
> }else {
> echo "There was an issue with your registration.. Please try again
> later";
> }
>
> }//Close Function
>
>
> if(!empty($errorCount)) {
>
>
> }else {
> //Build Email message
> $mailmessage = "Full Name: " . $_POST['firstname'] . " " .
> $_POST['lastname'] . "\n\n";
> $mailmessage .= "Address: " . $_POST['address'] . "\n\n";
> $mailmessage .= "City, State, Zip: " . $_POST['city'] . " " .
> $_POST['state'] . " " . $_POST['zip'] . "\n\n";
> $mailmessage .= "Phone: " . $_POST['phone'] . "\n\n";
> $mailmessage .= "Email address: " . $_POST['email'] . "\n\n";
> if($_POST['affiliation'] == "NFBOther") {
> $mailmessage .= "Chapter Affiliation: " . $_POST['other'] .
> "\n\n";
> }else{
> $mailmessage .= "Chapter Affiliation: " .
> $_POST['affiliation'] . "\n\n";
> }
> if($_POST['person'] =="Other"){
> $mailmessage .= "Who will pick up the ticket? " .
> $_POST['Pfirstname'] . " " . $_POST['Llastname'] . "\n\n";
>
> }else{
> $mailmessage .= "Who will pick up the ticket? I will pick it
> up my self! \n\n";
>
> }
>
> $mailmessage .= "Payment Method: " . $_POST['paymentMethod'];
>
> send_email($mailTo, $mailSubject, $mailmessage, $headers);
> }
>
> ?>
>
> Sometimes... It is dropping the last $mailmessage line... The payment method
> in the actual email it sends...
>
> Anyone have any ideas? I'm stumped....
------------
Hi there. First thought is perhaps it is not getting a value for
paymentMethod and if it doesn't exist, will the line still get added?
I would always check to see if every post variable isset, before adding
the line. Can write a default line in its place if missing.
George Langley
Interactive Developer
"RIP, Mr. Jobs."
--- End Message ---
--- Begin Message ---
Jason Pruim
[email protected]
On Oct 6, 2011, at 9:04 PM, George Langley wrote:
> On 2011-10-06, at 6:28 PM, Jason Pruim wrote:
>>
>> <?PHP
>>
>> //SETUP VARIABLES
>>
>> $mailTo = "[email protected]";
>> $mailFrom = "[email protected]";
>> //These 2 can be changed IF you know what you are doing and why!
>> $returnPath = $mailFrom;
>> $replyTo = $mailFrom;
>> $mailSubject = "New Convention registration!";
>>
>> $message = "";
>>
>> //DO NOT CHANGE UNDER PENALITY OF BEING SLAPPED WITH A WET NOODLE!!!
>>
>> $headers = "From: ".$mailFrom."\n";
>> $headers .= "Return-Path: ".$returnPath."\n";
>> $headers .= "Reply-To: ".$replyTo."\n";
>>
>> function send_email($mailTo, $mailSubject, $mailMessage, $headers) {
>>
>>
>> if(mail( $mailTo, $mailSubject, $mailMessage, $headers )) {
>>
>> $message = "Thank you for registering!";
>>
>> }else {
>> echo "There was an issue with your registration.. Please try again
>> later";
>> }
>>
>> }//Close Function
>>
>>
>> if(!empty($errorCount)) {
>>
>>
>> }else {
>> //Build Email message
>> $mailmessage = "Full Name: " . $_POST['firstname'] . " " .
>> $_POST['lastname'] . "\n\n";
>> $mailmessage .= "Address: " . $_POST['address'] . "\n\n";
>> $mailmessage .= "City, State, Zip: " . $_POST['city'] . " " .
>> $_POST['state'] . " " . $_POST['zip'] . "\n\n";
>> $mailmessage .= "Phone: " . $_POST['phone'] . "\n\n";
>> $mailmessage .= "Email address: " . $_POST['email'] . "\n\n";
>> if($_POST['affiliation'] == "NFBOther") {
>> $mailmessage .= "Chapter Affiliation: " . $_POST['other'] .
>> "\n\n";
>> }else{
>> $mailmessage .= "Chapter Affiliation: " .
>> $_POST['affiliation'] . "\n\n";
>> }
>> if($_POST['person'] =="Other"){
>> $mailmessage .= "Who will pick up the ticket? " .
>> $_POST['Pfirstname'] . " " . $_POST['Llastname'] . "\n\n";
>>
>> }else{
>> $mailmessage .= "Who will pick up the ticket? I will pick it
>> up my self! \n\n";
>>
>> }
>>
>> $mailmessage .= "Payment Method: " . $_POST['paymentMethod'];
>>
>> send_email($mailTo, $mailSubject, $mailmessage, $headers);
>> }
>>
>> ?>
>>
>> Sometimes... It is dropping the last $mailmessage line... The payment method
>> in the actual email it sends...
>>
>> Anyone have any ideas? I'm stumped....
> ------------
> Hi there. First thought is perhaps it is not getting a value for
> paymentMethod and if it doesn't exist, will the line still get added?
> I would always check to see if every post variable isset, before adding
> the line. Can write a default line in its place if missing.
The variable is being set with a default value of nothing else... But for some
reason it's not bringing it through when the form is submitted...
Any other ideas? hehe :)
--- End Message ---
--- Begin Message ---
On Thu, Oct 6, 2011 at 7:29 PM, Jason Pruim <[email protected]>wrote:
>
> Jason Pruim
> [email protected]
>
>
>
> On Oct 6, 2011, at 9:04 PM, George Langley wrote:
>
> > On 2011-10-06, at 6:28 PM, Jason Pruim wrote:
> >>
> >> <?PHP
> >>
> >> //SETUP VARIABLES
> >>
> >> $mailTo = "[email protected]";
> >> $mailFrom = "[email protected]";
> >> //These 2 can be changed IF you know what you are doing and why!
> >> $returnPath = $mailFrom;
> >> $replyTo = $mailFrom;
> >> $mailSubject = "New Convention registration!";
> >>
> >> $message = "";
> >>
> >> //DO NOT CHANGE UNDER PENALITY OF BEING SLAPPED WITH A WET NOODLE!!!
> >>
> >> $headers = "From: ".$mailFrom."\n";
> >> $headers .= "Return-Path: ".$returnPath."\n";
> >> $headers .= "Reply-To: ".$replyTo."\n";
> >>
> >> function send_email($mailTo, $mailSubject, $mailMessage, $headers) {
> >>
> >>
> >> if(mail( $mailTo, $mailSubject, $mailMessage, $headers )) {
> >>
> >> $message = "Thank you for registering!";
> >>
> >> }else {
> >> echo "There was an issue with your registration.. Please try again
> later";
> >> }
> >>
> >> }//Close Function
> >>
> >>
> >> if(!empty($errorCount)) {
> >>
> >>
> >> }else {
> >> //Build Email message
> >> $mailmessage = "Full Name: " . $_POST['firstname'] . " " .
> $_POST['lastname'] . "\n\n";
> >> $mailmessage .= "Address: " . $_POST['address'] . "\n\n";
> >> $mailmessage .= "City, State, Zip: " . $_POST['city'] . " " .
> $_POST['state'] . " " . $_POST['zip'] . "\n\n";
> >> $mailmessage .= "Phone: " . $_POST['phone'] . "\n\n";
> >> $mailmessage .= "Email address: " . $_POST['email'] . "\n\n";
> >> if($_POST['affiliation'] == "NFBOther") {
> >> $mailmessage .= "Chapter Affiliation: " . $_POST['other']
> . "\n\n";
> >> }else{
> >> $mailmessage .= "Chapter Affiliation: " .
> $_POST['affiliation'] . "\n\n";
> >> }
> >> if($_POST['person'] =="Other"){
> >> $mailmessage .= "Who will pick up the ticket? " .
> $_POST['Pfirstname'] . " " . $_POST['Llastname'] . "\n\n";
> >>
> >> }else{
> >> $mailmessage .= "Who will pick up the ticket? I will pick
> it up my self! \n\n";
> >>
> >> }
> >>
> >> $mailmessage .= "Payment Method: " . $_POST['paymentMethod'];
> >>
> >> send_email($mailTo, $mailSubject, $mailmessage, $headers);
> >> }
> >>
> >> ?>
> >>
> >> Sometimes... It is dropping the last $mailmessage line... The payment
> method in the actual email it sends...
> >>
> >> Anyone have any ideas? I'm stumped....
> > ------------
> > Hi there. First thought is perhaps it is not getting a value for
> paymentMethod and if it doesn't exist, will the line still get added?
> > I would always check to see if every post variable isset, before
> adding the line. Can write a default line in its place if missing.
>
> The variable is being set with a default value of nothing else... But for
> some reason it's not bringing it through when the form is submitted...
>
> Any other ideas? hehe :)
>
>
Have you tested with the same payment method to see if somewhere in your
code or a hiccup in the server is causing the problem? Does that happen to
any or certain payment method (including blank entry)? I'm guessing it may
happen with only certain payment method. From the line
if(!empty($errorCount)) {, I presume you have a mechanism in place to
sanitize and validate inputs? I'd suggest you start troubleshooting from
there. If this is still development phase, try to bypass that mechanism for
a quick confirmation that is causing the problem.
Regards,
Tommy
--- End Message ---