Results 1 to 3 of 3

Thread: [RESOLVED] Test for simplexml_load_file() support?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    121

    Resolved [RESOLVED] Test for simplexml_load_file() support?

    Code:
    /* INITIALIZE THE XML FILE */
    	$xml_file=@simplexml_load_file('path/to/my/file.txt');
    /* PERFORM AN ERROR TEST */
    	if($xml_file) {
    		/* LOOP THROUGH THE XML */
    			foreach($xml_file->xml_tag AS $tag) {
    				/* THE ARRAY */
    					// here i fill the array elements
    				/* INCREMENT THE VARIABLE */
    					$i+=1;
    			}
    	} else {
    		// my alternate code
    		// parse it another way...
    	}
    Hello all.
    Is there a way of determining whether or not a server supports simplexml, and if it does not, then go to my alternate code?
    Thanks in advance.
    Last edited by solitario; Jan 11th, 2008 at 09:22 AM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Test for simplexml_load_file() support?

    A call to undefined function always throws a fatal error in PHP. Fatal errors cannot be caught so your best option is to test it exists first. Use the extension_loaded / function_exists function:
    PHP Code:
    if (extension_loaded("simplexml")) {

    }

    // OR

    If (function_exists("simplexml_load_file")) {

    Also, if you are using PHP 4 simple XML will not be available you can test this with the phpversion function too. The simplest way is - function_exists.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    121

    Re: Test for simplexml_load_file() support?

    Beautiful. Thanks again VisualAd.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width