PHP sscanf() ফাংশন

উদাহরণ

প্রদর্শন করা হল:

<?php
$str = "age:30 weight:60kg";
sscanf($str,"age:%d weight:%dkg",$age,$weight);
// ধরন ও মান প্রদর্শন
var_dump($age,$weight);
?>

Run Instance

সংজ্ঞা ও ব্যবহার

sscanf() ফাংশন স্ট্রিং থেকে নাগাল প্রদর্শন করে। sscanf() ফাংশন ফরম্যাট স্ট্রিং ভিত্তিতে ডাটা পারস্পরিকভাবে ডেকে থাকা ডাটা প্রদর্শন করে。

যদি এই ফাংশনের কাছে দুইটি পারামিটার পাঠানো হয়, তবে ডাটা একটি আইনমূলক বাস্তুর রূপে ফিরে আসবে। যদি অতিরিক্ত পারামিটার পাঠানো হয়, তবে পারস্পরিকভাবে ডেকে থাকা ডাটা এই পারামিটারগুলিতে সংরক্ষিত হবে। যদি ডিসটিগ্রেফারের সংখ্যা ডাটা সংখ্যা থেকে বেশি থাকে, তবে ভুল হবে। কিন্তু যদি ডিসটিগ্রেফারের সংখ্যা ডাটা সংখ্যা থেকে কম থাকে, তবে অতিরিক্ত বদলে নালা হবে。

সংশ্লিষ্ট ফাংশন:

  • printf() - ফরম্যাট করা স্ট্রিং প্রদর্শন
  • sprintf() - একটি ফরম্যাট করা স্ট্রিং বদলে একটি বদলে প্রদর্শন

বিষয়

sscanf(string,format,arg1,arg2,arg++)
পারামিটার বর্ণনা
string আবশ্যিক। পঠন করতে নির্ধারিত স্ট্রিং
format

আবশ্যিক। ব্যবহারযোগ্য ফরম্যাট নির্ধারণ

সম্ভাব্য ফরম্যাট মানসমূহ:

  • %% - % হিসাবে ফলাফল প্রদান
  • %c - ASCII মূল্যের অনুরূপ অক্ষর
  • %d - নেগেটিভ, 0 বা পজিটিভ দশমিক সংখ্যা
  • %e - ছোট বৈজ্ঞানিক পদার্থ ব্যবহার করে (উদাহরণ 1.2e+2)
  • 踁েগেটিভ নয় দশমিক সংখ্যা (অধিকতম 0)
  • %f - ফ্লোটিং পদার্থ
  • %o - 8 অক্ষর সংখ্যা
  • %s - স্ট্রিং
  • 0x - 16 অক্ষর সংখ্যা (ছোট অক্ষর)
  • %X - Hexadecimal number (uppercase letters)}

Additional format values. Must be placed between % and the letter (e.g. %.2f):

  • + (add + or - in front of the number to define the sign of the number. By default, only negative numbers are marked, positive numbers are not marked)
  • ' (specifies what to use as padding, default is space. It must be used with the width specifier.)
  • - (left align the variable value)
  • .[0-9] (specifies the minimum width of the variable value)
  • .[0-9] (specifies the number of decimal places or the maximum string length)

Note:If multiple of the above format values are used, they must be used in the order listed above.

arg1 Optional. The first variable storing data.
arg2 Optional. The second variable storing data.
arg++ Optional. The third, fourth variables storing data, and so on.

Technical Details

Return Value: If only two parameters are passed to this function, the data will be returned in array form. Otherwise, if additional parameters are passed, the parsed data will be stored in these parameters. If the number of delimiters is greater than the number of variables containing them, an error will occur. However, if the number of delimiters is less than the number of variables containing them, the additional variables will contain NULL.
PHP Version: 4.0.1+

More Examples

Example 1

Use format values %s, %d, and %c:

<?php
$str = "If you divide 4 by 2 you'll get 2";
$format = sscanf($str,"%s %s %s %d %s %d %s %s %c");
print_r($format);
?>

Run Instance