3v4l.org

run code in 300+ PHP versions simultaneously
<?xml version="1.0" encoding="utf-8"?> <student> <data> <name> Utham Kumar </name> <course> MCA </course> <sem> 4 </sem> <email> iamutham@gmail.com </email> </data> <data> <name> Utham </name> <course> MCA </course> <sem> 2 </sem> <email> iamutham@gmail.com </email> </data> </student> $doc = new DOMDocument(); <?php $student = $doc->getElementsByTagName("data"); foreach($student as $data) { $names = $data->getElementsByTagName("name"); $name = $names->item(0)->nodeValue; $courses = $data->getElementsByTagName("course"); $course = $courses->item(0)->nodeValue; $semister = $data->getElementsByTagName("sem"); $sem = $semister->item(0)->nodeValue; $emails = $data->getElementsByTagName("email"); $email = $emails->item(0)->nodeValue; }
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<?xml version="1.0" encoding="utf-8"?> <student> <data> <name> Utham Kumar </name> <course> MCA </course> <sem> 4 </sem> <email> iamutham@gmail.com </email> </data> <data> <name> Utham </name> <course> MCA </course> <sem> 2 </sem> <email> iamutham@gmail.com </email> </data> </student> $doc = new DOMDocument(); Warning: Undefined variable $doc in /in/TA5tZ on line 19 Fatal error: Uncaught Error: Call to a member function getElementsByTagName() on null in /in/TA5tZ:19 Stack trace: #0 {main} thrown in /in/TA5tZ on line 19
Process exited with code 255.
Output for 8.0.13
Parse error: syntax error, unexpected identifier "version" in /in/TA5tZ on line 1
Process exited with code 255.
Output for 5.4.0 - 5.4.28, 5.5.0 - 5.5.12, 7.3.32 - 7.3.33, 7.4.26, 7.4.33
Parse error: syntax error, unexpected 'version' (T_STRING) in /in/TA5tZ on line 1
Process exited with code 255.
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.31, 7.4.3 - 7.4.25, 7.4.27 - 7.4.32
<?xml version="1.0" encoding="utf-8"?> <student> <data> <name> Utham Kumar </name> <course> MCA </course> <sem> 4 </sem> <email> iamutham@gmail.com </email> </data> <data> <name> Utham </name> <course> MCA </course> <sem> 2 </sem> <email> iamutham@gmail.com </email> </data> </student> $doc = new DOMDocument(); Notice: Undefined variable: doc in /in/TA5tZ on line 19 Fatal error: Uncaught Error: Call to a member function getElementsByTagName() on null in /in/TA5tZ:19 Stack trace: #0 {main} thrown in /in/TA5tZ on line 19
Process exited with code 255.
Output for 5.0.4 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.28
<?xml version="1.0" encoding="utf-8"?> <student> <data> <name> Utham Kumar </name> <course> MCA </course> <sem> 4 </sem> <email> iamutham@gmail.com </email> </data> <data> <name> Utham </name> <course> MCA </course> <sem> 2 </sem> <email> iamutham@gmail.com </email> </data> </student> $doc = new DOMDocument(); Notice: Undefined variable: doc in /in/TA5tZ on line 19 Fatal error: Call to a member function getElementsByTagName() on a non-object in /in/TA5tZ on line 19
Process exited with code 255.
Output for 5.0.0 - 5.0.3
<?xml version="1.0" encoding="utf-8"?> <student> <data> <name> Utham Kumar </name> <course> MCA </course> <sem> 4 </sem> <email> iamutham@gmail.com </email> </data> <data> <name> Utham </name> <course> MCA </course> <sem> 2 </sem> <email> iamutham@gmail.com </email> </data> </student> $doc = new DOMDocument(); Notice: Undefined variable: doc in /in/TA5tZ on line 19 Fatal error: Call to a member function getElementsByTagName() on a non-object in /in/TA5tZ on line 19
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/TA5tZ on line 23
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/TA5tZ on line 23
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/TA5tZ on line 23
Process exited with code 255.

preferences:
212.75 ms | 401 KiB | 264 Q