PHP sprintf, str_pad, nl2br Quiz हिंदी में — 20 Questions
PHP String Functions Quiz हिंदी में — sprintf(), number_format(), str_pad(), str_repeat(), nl2br() से जुड़े 20 important questions real examples के साथ। BCA, MCA, BSc students के लिए।
-
sprintf() और printf() में सबसे बड़ा फर्क क्या है?
- sprintf() string return करता है — variable में store, function में pass कर सकते हो; printf() directly print करता है
- printf() string return करता है, sprintf() print करता है
- दोनों same काम करते हैं — कोई फर्क नहीं
- sprintf() सिर्फ PHP 8 में है
-
sprintf("ORD-%05d", 42) का output क्या होगा?
- "ORD-00042" — %05d यानी 5 chars wide, left में zeros
- "ORD-42"
- "ORD-42000"
- "ORD-%05d"
-
sprintf("%.2f", 3.1) का output क्या होगा?
- "3.10" — 2 decimal places fixed
- "3.1"
- "3.100000"
- "3"
-
CSS hex color बनाने के लिए कौन सा sprintf code सही है?
- sprintf("#%02x%02x%02x", $r, $g, $b) — %02x यानी 2 char hex, zero padded
- sprintf("#%d%d%d", $r, $g, $b)
- sprintf("#%s%s%s", $r, $g, $b)
- sprintf("#%03d%03d%03d", $r, $g, $b)
-
number_format(1234567.891, 2) का output क्या होगा?
- "1,234,567.89" — thousands separator comma, 2 decimal places
- "1234567.89"
- "1,234,568"
- "12,34,567.89"
-
number_format() के बारे में tutorial में कौन सी common mistake बताई गई है?
- number_format() string return करता है — इसके result पर arithmetic मत करो, पहले calculate करो फिर format करो
- number_format() सिर्फ integers पर काम करता है
- number_format() negative numbers support नहीं करता
- number_format() PHP 8 में remove हो गया
-
European style में number format करने के लिए कौन सा code सही है?
- number_format($price, 2, ",", ".") — comma decimal, dot thousands
- number_format($price, 2, ".", ",") — dot decimal, comma thousands
- number_format($price, 2, ".", ".")
- number_format($price, ",", ".", 2)
-
GST calculation में पहले क्या करना चाहिए?
- पहले $total = $base + $gst calculate करो, फिर number_format($total, 2) से display करो
- पहले number_format() से format करो, फिर add करो
- GST के लिए number_format() की ज़रूरत नहीं
- sprintf() से GST display करो — number_format() से नहीं
-
str_pad("PHP", 10) का default output क्या होगा?
- "PHP " — right side में 7 spaces add होंगे (STR_PAD_RIGHT default है)
- " PHP" — left side में spaces
- " PHP " — दोनों sides
- "PHP0000000" — zeros से pad
-
Order number "ORD-000042" बनाने के लिए कौन सा code सही है?
- "ORD-" . str_pad($ordNum, 6, "0", STR_PAD_LEFT)
- "ORD-" . str_pad($ordNum, 6, "0", STR_PAD_RIGHT)
- "ORD-" . str_pad($ordNum, 6, "0", STR_PAD_BOTH)
- "ORD-" . sprintf("%d", $ordNum)
-
str_pad() के तीन padding constants कौन से हैं?
- STR_PAD_RIGHT (default), STR_PAD_LEFT, STR_PAD_BOTH
- STR_PAD_LEFT (default), STR_PAD_RIGHT, STR_PAD_CENTER
- STR_PAD_START, STR_PAD_END, STR_PAD_BOTH
- STR_LEFT, STR_RIGHT, STR_BOTH
-
sprintf("%06d", 42) और str_pad("42", 6, "0", STR_PAD_LEFT) — दोनों का output क्या है?
- दोनों "000042" देते हैं — sprintf concise है, str_pad custom characters के लिए ज़्यादा flexible
- दोनों अलग-अलग output देते हैं
- सिर्फ sprintf सही है
- सिर्फ str_pad सही है
-
str_repeat("ab", 4) का output क्या होगा?
- "abababab" — "ab" 4 बार repeat
- "aaaa"
- "bbbb"
- "ab4"
-
str_repeat($string, 0) का output क्या होगा?
- Empty string "" — 0 बार repeat = कुछ नहीं
- "0"
- Error आएगी
- false return होगा
-
Progress bar बनाने के लिए कौन सा code tutorial में बताया गया है?
- $filled = str_repeat("█", $percent); $empty = str_repeat("░", 100 - $percent);
- $bar = str_pad("", $percent, "█");
- $bar = sprintf("%d%%", $percent);
- $bar = number_format($percent) . "%";
-
str_repeat() के $times parameter में negative number pass करने पर क्या होगा?
- ValueError आएगी — times 0 या उससे ज़्यादा होना चाहिए
- Empty string return होगी
- String reverse होकर आएगी
- false return होगा
-
nl2br() function क्या करता है?
- String के \n (newlines) को HTML <br> tag में convert करता है
- HTML <br> tags को \n में convert करता है
- String को नई line पर print करता है
- Newlines को spaces में बदलता है
-
User का textarea input browser में newlines के साथ display करने के लिए कौन सा code सही है?
- echo nl2br(htmlspecialchars($userInput)) — पहले XSS safe करो, फिर nl2br
- echo nl2br($userInput) — directly use करो
- echo htmlspecialchars(nl2br($userInput))
- echo str_replace("\n", "<br>", $userInput)
-
nl2br("Hello\nWorld") का output क्या होगा?
- "Hello<br />\nWorld" — <br /> insert होता है, original \n भी रहता है
- "Hello<br>World" — \n remove हो जाता है
- "Hello World" — newline space बन जाता है
- "HelloWorld" — newline हट जाता है
-
nl2br() का सबसे common real-world use case कौन सा है?
- User का comment या textarea input HTML में properly display करना
- Email body में newlines add करना
- Database से text निकालकर format करना
- PHP की echo में newline print करना