PHP xml_set_default_handler() ফাংশন
সংজ্ঞা ও ব্যবহার
xml_set_default_handler() ফাংশন এক্সিমল পার্সারকে ডিফলট ডাটা হ্যান্ডলার তৈরি করে
এই ফাংশনটি পার্সারটি এক্সিমল ফাইলে ডাটা খুঁজে পায় তখন ফাংশনটি অনুমোদিত করে
যদি হ্যান্ডলার সফলভাবে তৈরি হয়, তবে এই ফাংশন ট্রু ফিরবে; নাকি ফলা হলে false ফিরবে。
ব্যবহারিকতা
xml_set_default_handler(parser,handler)
প্যারামিটার | বিবরণ |
---|---|
parser | বাধ্যতামূলক। ব্যবহার করতে হলে XML পার্সার নির্দিষ্ট করুন |
handler | বাধ্যতামূলক। ইভেন্ট হ্যান্ডলার হিসাবে ব্যবহার করা ফাংশনটি নির্দিষ্ট করুন |
দ্বারা handler প্যারামিটারটির নির্দিষ্ট ফাংশনটি তিনটি প্যারামিটার থাকতে হবে:
প্যারামিটার | বিবরণ |
---|---|
parser | বাধ্যতামূলক। একটি বিন্যাসকৃত নির্দিষ্ট একটি বিন্যাসকৃত এক্সিমল পার্সার ডিফলট হ্যান্ডলার |
data | বাধ্যতামূলক। ডাটার বিন্যাসকৃত বিন্যাসকৃত |
বিবরণ
handler প্যারামিটারটি একটি অ্যারেও হতে পারে যা ওবজেক্ট রেফারেন্স এবং মথড নাম ধারণ করে。
Example
XML File:
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note>
PHP Code:
<?php $parser=xml_parser_create(); function default($parser,$data) { echo $data; } xml_set_default_handler($parser,"default"); $fp=fopen("test.xml","r"); while ($data=fread($fp,4096)) { xml_parse($parser,$data,feof($fp)) or die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); } xml_parser_free($parser); ?>
Output:
George John Reminder Don't forget the meeting!
If you view the source code in the browser, you will see the following HTML:
<note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note>