473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

method to parse CDATA as php

Dormilich
8,658 Expert Mod 8TB
Hello,

I've got a problem with a xsl output (see former xsl thread) resulting in php code (inserted via <xsl:processing-instruction>) printed out to the page and not parsed.

Right now I have a workaround for that, but I consider it rather, er, crude
Expand|Select|Wrap|Line Numbers
  1. <!-- previous html code from the site script -->
  2. <?php
  3. // $inhalt as instance of a custom class defined elsewhere
  4.     if ($text = $inhalt->DataInhalt()) {   // apply only if content comes from the xslt processing
  5.         $suche = '@<\?php([^\?]+)\?>@';    // get the PIs
  6.         preg_match_all($suche, $text, $treffer, PREG_OFFSET_CAPTURE);
  7.         $start = 0;
  8.         foreach ($treffer[0] as $key => $val) {
  9.             echo substr($text, $start, $val[1]-$start);  // split the text and print it
  10.             $start = $val[1] + strlen($val[0]);
  11.             eval(trim($treffer[1][$key][0]));     // process the php code
  12.         }
  13.         echo substr($text, $start);
  14.     }
  15. ?>
  16. <!--  further html code  -->
  17.  
I know that the regex is not the best but '/<\?php(.+)\?>/' didn't work out.

I would have used something like preg_replace_callback() but callback functions can't use eval().

Unfortunately I'm not able to do the processing in the class itself, because the object that is to be processed in the xsl code produces an error (respectively a script exit) when called inside the outer class...

I've even tried to set the xsl result mime type to text/php but no response from the parser.

Any ideas to clean that code up are highly appreciated


Thanks in advance, Dormilich

(involved files are shown in the above mentioned thead)
Aug 28 '08 #1
1 2334
Dormilich
8,658 Expert Mod 8TB
most problems solved

- found that in the regex the whitespace was making trouble, now using '@<\?php\s*(.+)\s*\?>@'

- calling the "inside" class now works (probably writing mistake)

- I realized that php is not likely to parse strings, so I have to save the result to a file if I want to do it without eval

Nevertheless, has someone an idea to overcome the callback obstacle?

thanks to myself *gg*
Sep 1 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Francesco Moi | last post by:
Hi. I must parse this XML document: -------------- <doc> <item> <name>Jerry</name> <message>Hi<br>My name is Jerry</message> </item> </doc>
10
by: Andrey Tatarinov | last post by:
Hi all! Is it possible to create method epilog in C++? It means that I want to define such code in base class, that would be executed _after_ execution of overrided method in child class,...
6
by: Cade Perkins | last post by:
How can the CDATA ending delimiter "]]>" be represented within a CDATA section itself? Consider an XML document that is intended to contain an embedded, uninterpreted XML example. Generally,...
10
by: Russell Mangel | last post by:
What would be the best way to parse this XML document? I want to avoid using XMLDocument. I don't know if I should use XMLTextReader, or Xpath classes. There is only one element <MessageStore>...
11
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
2
by: C | last post by:
Hi, I have an XML doc as below <WebSRFTemplate Version="1" Type="SERVICE"> <Data> <Field Name="SERVICEStaticRoute2IPnetwork1"><!]></Field> </Data> </WebSRFTemplate>
7
by: Max | last post by:
Hello everyone! Can anyone help me to convert the CDATA expression "CDATA ::= (Char* - (Char* ']]>' Char*)" to Javascript Regular Expression? Thanks, Max
0
by: Peter Parker | last post by:
I am using php5 to parse node content from a xml file. Could someone show me if it's possible to to print the content without the !] tags in the following codes ? Thank you in advance .......
6
by: dkyadav80 | last post by:
Hi sir, I'm new about xml, javascript. I have two selection field(html) first is city and second is state. the city and state values should be store in xml file. when user select city then all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.