[PHP] evaluating php expressions using Sablotron
Hi, I am using php >4.1, with Sablotron. I have both an xml and xsl file, and use sablotron to output html. But the php expressions inside these files are not evaluated (i.e. left out in the html-file) How can they be evaluated for sure? (most examples use sablotron with php4.0 and are therefore not of much use...) Here is what I have: index.php: PHP: 'PIHandler')); // process the two files to get the desired output $result = xslt_process($xslthandler, $xmlfilename, $xslfilename); if ($result) { echo $result; } else { print "Sorry, \$xmlfile could not be transformed by \$xslfile into"; print " the \$result variable. Reason: " . xslt_error($xslthandler); print ". Error code: " . xslt_errno($xslthandler); } // free the resources occupied by the xslthandler xslt_free($xslthandler); // processing instruction handler function PIHandler($parser, $data, $target) { echo $data; // not working... switch (strtolower($target)) { case "php": eval("?>$data"); // not working... echo Date("Y"); // blah... break; } } ?> processing instruction handler isn't working... $target contains 'php' when found an pi. But the $data does contains 'blah blah' (no data). Further it does process the code inside the pihandler, but I still can't pass php code to it. (in php4.0 the arguments were like in: function PIHandler($parser, $target, $data), I changed the order, so that $target contains 'php' when an pi is encountered) The xml file contains sometimes pieces of php code like: PHP: -- The xsl-file contains a piece like: PHP: hello echo "hello"; But nothing seems to work... -- It's really frustrating: I mean, I just want to evaluate some php code inside the xml and xsl files. What's the big deal? Why should this be so complicated? Please help. Jerome wrote: "if you us ob_*() functions, instead of writing HTML pages with php tags inserted, you can write XML pages with PHP tags inserted. then after you're done, you can pass the contents of the output buffer to an XSLT processer like sablotron, THEN outputting an HTML page." Can someone show me how using an example? Thanks, Richard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] expressions
[re-arranging quotes to bottom posting] In article <9556pp$sna$[EMAIL PROTECTED]>, [EMAIL PROTECTED] ("Jeff Warrington") wrote: > > hi, im trying to fix this couple of hours but i couldnt find the > > mistake... can somebody look at it... > > > > first i want to check the $co_area for 3 digital ... it must contain 3 > > digital > > > > if ($co_area != !ereg("([0-9]{3})",$co_area)) > > { echo " * Area code must be 3 digital"; } > if (eregi("[^0-9]{3}",$co_area)) { > print("area code must be digits"); > } > > or > > if (eregi("[^[:digit:]]{3}",$co_area)) > > if you use the POSIX regex fields. Those pass any string except where there occurs a sequence of three non-digit chars. So "123AB", "AB", "A", "1 2 3", etc. would all slip through as apparently valid area codes. Instead, how about: //<-if anything but a sequence of exactly three digits from beginning to end... if (!eregi("^[[:digit:]]{3}$",$co_area)) { //throw an error message echo "Sorry, only a three digit area code is permitted!"; } -- CC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] expressions
In article <94t6hv$903$[EMAIL PROTECTED]>, "Kumanan" <[EMAIL PROTECTED]> wrote: if (eregi("[^0-9]{3}",$co_area)) { print("area code must be digits"); } or if (eregi("[^[:digit:]]{3}",$co_area)) if you use the POSIX regex fields. > hi, im trying to fix this couple of hours but i couldnt find the > mistake... can somebody look at it... > > first i want to check the $co_area for 3 digital ... it must contain 3 > digital > > if ($co_area != !ereg("([0-9]{3})",$co_area)) > { echo " * Area code must be 3 digital"; } > > > second... > > nickname check works but the first letter could be any number or any > letters > > with this code it accept only letters as first character... i just > want any letter or numbers or - _ symboles from 3 to 12 characters... > > if ($nickname != !eregi("^[-\._\.0-9a-zA-Z]{3,12}$",$nickname)) > { > $error ="Nickname must be Alphanumeric[ a-z 0-9; - _ ; 3 - 12 > characters ]"; > $flak=1; > } > First mistake when using character classes in the pattern is that the hyphen must be at the end if it is to be included. Otherwise the hyphen is seen to be part of the range (0-9 or A-Z): so, ^[0-9a-zA-Z._-]{3,12} instead of what you have. You also should not need the trailing $. As in the first example, don't use the 'double negative' approach. use: if (eregi("^[^0-9a-zA-z._-]{3,12}",$nickname)) { echo "only alphanumeric buddy!"; } I didn't test this but it should be closer to success. Jeff > > i hope someone can help me to fix this... > > thanx > > kumanan [EMAIL PROTECTED] > > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] expressions
> if ($co_area != !ereg("([0-9]{3})",$co_area)) > { echo " * Area code must be 3 digital"; } I don't know anything about ereg and regex, so if there's an error in that part I won't be able to help with that, but I can tell you that ($something != !$something_else) is a double negative, it's like saying "I can't not program in PHP." You might as well say ($something == $something_else), save the obfuscation factor. Since you want to do something when ereg is false, you should say: if (!ereg(...)) { Do a bunch of stuff; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] expressions
hi, im trying to fix this couple of hours but i couldnt find the mistake... can somebody look at it... first i want to check the $co_area for 3 digital ... it must contain 3 digital if ($co_area != !ereg("([0-9]{3})",$co_area)) { echo " * Area code must be 3 digital"; } second... nickname check works but the first letter could be any number or any letters with this code it accept only letters as first character... i just want any letter or numbers or - _ symboles from 3 to 12 characters... if ($nickname != !eregi("^[-\._\.0-9a-zA-Z]{3,12}$",$nickname)) { $error ="Nickname must be Alphanumeric[ a-z 0-9; - _ ; 3 - 12 characters ]"; $flak=1; } i hope someone can help me to fix this... thanx kumanan [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]