3v4l.org

run code in 300+ PHP versions simultaneously
<?php $code = ' <pre class="prettyprint"><?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title> SimpleXML Example</title> </head> <body> <h1> Please go <a href="http://www.ucertify.com">http://www.ucertify.com</a> <br/> </h1> </body> </html> </pre> Which of the following statements will display the HREF attribute on the anchor tag if the SimpleXML object is $sxml? | In the script given in the question, HREF is the attribute of the anchor (<a>) tag. Besides this, anchor tag is inside the <h1> tag and <body> tag. Hence, you will access the HREF tag in the following way: <pre class="prettyprint">$sxml->body->h1->a[\'href\']</pre> Fact What is SimpleXML? SimpleXML is a PHP extension that allows users to easily manipulate/use XML data. Its functions let a user convert XML to an object, which can be processed with property selectors and array iterators. Consider the following XML file, which describes a small collection of books in XML format. It has a root node of store having a direct child, i.e., category, which classifies the books as fiction; category has two children() labelled book; "twilight" by Stephinie Mayer and "The Bikers" by Alex R. Stuart. <pre class="prettyprint"><?xml version="1.0"?> <store> <category id="fiction"> <book> <title>twilight</title> <author>Stephinie Mayer</author> </book> <book> <title>The Bikers</title> <author>Alex R. Stuart</author> </book> </category> </store> </pre> To extract the book title and author, a user will run the following PHP script: <pre class="prettyprint"><?php $store = simplexml_load_file(\'store.xml\'); foreach ($store->category as $category) { printf("Category %s\n", $category[\'id\']); foreach ($category->book as $book) { printf("<br>Title: %s\n", $book->title); printf("<br>Author: %s\n", $book->author); } } ?></pre> '; \libxml_use_internal_errors(true); $dom = new \DomDocument('1.0', 'utf8'); $dom->loadHtml($code, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $elements = $dom->getElementsByTagName('pre'); foreach($elements as $code){ $newNode = $dom->createElement('pre'); $newNode->setAttribute('class', 'prettyprint'); $text = new \DOMText(htmlentities($code->nodeValue)); $newNode->appendChild($text); $code->parentNode->replaceChild($newNode, $code); } var_dump($dom->saveHtml());
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 44
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 44
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/WdPR8
function name:  (null)
number of ops:  51
compiled vars:  !0 = $code, !1 = $dom, !2 = $elements, !3 = $newNode, !4 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%0A%3Cpre+class%3D%22prettyprint%22%3E%3C%3Fxml+version%3D%221.0%22+encoding%3D%22ISO-8859-1%22+%3F%3E+%0A%3C%21DOCTYPE+html+%0APUBLIC+%22-%2F%2FW3C%2F%2FDTD+XHTML+1.0+Transitional%2F%2FEN%22+%0A%22http%3A%2F%2Fwww.w3.org%2FTR%2Fxhtml1%2FDTD%2Fxhtml1-transitional.dtd%22%3E+%0A%3Chtml+xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22+xml%3Alang%3D%22en%22+lang%3D%22en%22%3E+%0A%3Chead%3E+%0A%3Ctitle%3E+SimpleXML+Example%3C%2Ftitle%3E+%0A%3C%2Fhead%3E+%0A%3Cbody%3E+%0A%3Ch1%3E+%0APlease+go+%3Ca+href%3D%22http%3A%2F%2Fwww.ucertify.com%22%3Ehttp%3A%2F%2Fwww.ucertify.com%3C%2Fa%3E+%0A%3Cbr%2F%3E+%0A%3C%2Fh1%3E+%0A%3C%2Fbody%3E+%0A%3C%2Fhtml%3E+%3C%2Fpre%3E%0A%0AWhich+of+the+following+statements+will+display+the+HREF+attribute+on+the+anchor+tag+if+the+SimpleXML+object+is+%24sxml%3F+%7C+In+the+script+given+in+the+question%2C+HREF+is+the+attribute+of+the+anchor+%28%3Ca%3E%29+tag.+Besides+this%2C+anchor+tag+is+inside+the+%3Ch1%3E+tag+and+%3Cbody%3E+tag.+Hence%2C+you+will+access+the+HREF+tag+in+the+following+way%3A%0A%0A%3Cpre+class%3D%22prettyprint%22%3E%24sxml-%3Ebody-%3Eh1-%3Ea%5B%27href%27%5D%3C%2Fpre%3E%0A%0AFact+What+is+SimpleXML%3F%0ASimpleXML+is+a+PHP+extension+that+allows+users+to+easily+manipulate%2Fuse+XML+data.+Its+functions+let+a+user+convert+XML+to+an+object%2C+which+can+be+processed+with+property+selectors+and+array+iterators.+Consider+the+following+XML+file%2C+which+describes+a+small+collection+of+books+in+XML+format.+It+has+a+root+node+of+store+having+a+direct+child%2C+i.e.%2C+category%2C+which+classifies+the+books+as+fiction%3B+category+has+two+children%28%29+labelled+book%3B+%22twilight%22+by+Stephinie+Mayer+and+%22The+Bikers%22+by+Alex+R.+Stuart.+%0A%0A%3Cpre+class%3D%22prettyprint%22%3E%3C%3Fxml+version%3D%221.0%22%3F%3E+%0A%3Cstore%3E%0A+++%3Ccategory+id%3D%22fiction%22%3E+%0A++++++%3Cbook%3E+%0A+++++++++%3Ctitle%3Etwilight%3C%2Ftitle%3E+%0A+++++++++%3Cauthor%3EStephinie+Mayer%3C%2Fauthor%3E+%0A++++++%3C%2Fbook%3E+%0A++++++%3Cbook%3E+%0A+++++++++%3Ctitle%3EThe+Bikers%3C%2Ftitle%3E+%0A+++++++++%3Cauthor%3EAlex+R.+Stuart%3C%2Fauthor%3E+%0A++++++%3C%2Fbook%3E+%0A+++%3C%2Fcategory%3E+%0A%3C%2Fstore%3E%0A%3C%2Fpre%3E%0A%0ATo+extract+the+book+title+and+author%2C+a+user+will+run+the+following+PHP+script%3A%0A%0A%3Cpre+class%3D%22prettyprint%22%3E%3C%3Fphp+%0A+++%24store+%3D+simplexml_load_file%28%27store.xml%27%29%3B%0A++++++foreach+%28%24store-%3Ecategory+as+%24category%29+%7B+%0A++++++printf%28%22Category+%25s%5Cn%22%2C+%24category%5B%27id%27%5D%29%3B+%0A+++++++++foreach+%28%24category-%3Ebook+as+%24book%29+%7B+%0A+++++++++printf%28%22%3Cbr%3ETitle%3A+%25s%5Cn%22%2C+%24book-%3Etitle%29%3B+%0A+++++++++printf%28%22%3Cbr%3EAuthor%3A+%25s%5Cn%22%2C+%24book-%3Eauthor%29%3B+%0A++++++%7D+%0A+++%7D+%0A%3F%3E%3C%2Fpre%3E%0A'
   56     1        INIT_FCALL                                               'libxml_use_internal_errors'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                                 
   58     4        NEW                                              $7      'DomDocument'
          5        SEND_VAL_EX                                              '1.0'
          6        SEND_VAL_EX                                              'utf8'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $7
   59     9        INIT_METHOD_CALL                                         !1, 'loadHtml'
         10        SEND_VAR_EX                                              !0
         11        SEND_VAL_EX                                              8196
         12        DO_FCALL                                      0          
   61    13        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         14        SEND_VAL_EX                                              'pre'
         15        DO_FCALL                                      0  $11     
         16        ASSIGN                                                   !2, $11
   63    17      > FE_RESET_R                                       $13     !2, ->44
         18    > > FE_FETCH_R                                               $13, !0, ->44
   64    19    >   INIT_METHOD_CALL                                         !1, 'createElement'
         20        SEND_VAL_EX                                              'pre'
         21        DO_FCALL                                      0  $14     
         22        ASSIGN                                                   !3, $14
   66    23        INIT_METHOD_CALL                                         !3, 'setAttribute'
         24        SEND_VAL_EX                                              'class'
         25        SEND_VAL_EX                                              'prettyprint'
         26        DO_FCALL                                      0          
   67    27        NEW                                              $17     'DOMText'
         28        INIT_FCALL                                               'htmlentities'
         29        FETCH_OBJ_R                                      ~18     !0, 'nodeValue'
         30        SEND_VAL                                                 ~18
         31        DO_ICALL                                         $19     
         32        SEND_VAR_NO_REF_EX                                       $19
         33        DO_FCALL                                      0          
         34        ASSIGN                                                   !4, $17
   68    35        INIT_METHOD_CALL                                         !3, 'appendChild'
         36        SEND_VAR_EX                                              !4
         37        DO_FCALL                                      0          
   70    38        FETCH_OBJ_R                                      ~23     !0, 'parentNode'
         39        INIT_METHOD_CALL                                         ~23, 'replaceChild'
         40        SEND_VAR_EX                                              !3
         41        SEND_VAR_EX                                              !0
         42        DO_FCALL                                      0          
   63    43      > JMP                                                      ->18
         44    >   FE_FREE                                                  $13
   74    45        INIT_FCALL                                               'var_dump'
         46        INIT_METHOD_CALL                                         !1, 'saveHtml'
         47        DO_FCALL                                      0  $25     
         48        SEND_VAR                                                 $25
         49        DO_ICALL                                                 
         50      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.42 ms | 1404 KiB | 19 Q