1--TEST-- 2Test mb_encode_mimeheader() function : usage variations - Pass different data types to $indent arg 3--SKIPIF-- 4<?php 5extension_loaded('mbstring') or die('skip'); 6function_exists('mb_encode_mimeheader') or die("skip mb_encode_mimeheader() is not available in this build"); 7?> 8--FILE-- 9<?php 10/* Prototype : string mb_encode_mimeheader 11 * (string $str [, string $charset [, string $transfer_encoding [, string $linefeed [, int $indent]]]]) 12 * Description: Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?= 13 * Source code: ext/mbstring/mbstring.c 14 */ 15 16/* 17 * Pass different data types to $indent argument to see how mb_encode_mimeheader() behaves 18 */ 19 20echo "*** Testing mb_encode_mimeheader() : usage variations ***\n"; 21 22mb_internal_encoding('utf-8'); 23 24// Initialise function arguments not being substituted 25$str = base64_decode('zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg=='); 26$charset = 'utf-8'; 27$transfer_encoding = 'B'; 28$linefeed = "\r\n"; 29 30//get an unset variable 31$unset_var = 10; 32unset ($unset_var); 33 34// get a class 35class classA 36{ 37 public function __toString() { 38 return "Class A object"; 39 } 40} 41 42// heredoc string 43$heredoc = <<<EOT 44hello world 45EOT; 46 47// get a resource variable 48$fp = fopen(__FILE__, "r"); 49 50// unexpected values to be passed to $indent argument 51$inputs = array( 52 53 // int data 54/*1*/ 0, 55 1, 56 12345, 57 -2345, 58 59 // float data 60/*5*/ 10.5, 61 -10.5, 62 12.3456789000e10, 63 12.3456789000E-10, 64 .5, 65 66 // null data 67/*10*/ NULL, 68 null, 69 70 // boolean data 71/*12*/ true, 72 false, 73 TRUE, 74 FALSE, 75 76 // empty data 77/*16*/ "", 78 '', 79 80 // string data 81/*18*/ "string", 82 'string', 83 $heredoc, 84 85 // object data 86/*21*/ new classA(), 87 88 // undefined data 89/*22*/ @$undefined_var, 90 91 // unset data 92/*23*/ @$unset_var, 93 94 // resource variable 95/*24*/ $fp 96); 97 98// loop through each element of $inputs to check the behavior of mb_encode_mimeheader() 99$iterator = 1; 100foreach($inputs as $input) { 101 echo "\n-- Iteration $iterator --\n"; 102 var_dump( mb_encode_mimeheader($str, $charset, $transfer_encoding, $linefeed, $input)); 103 $iterator++; 104}; 105 106fclose($fp); 107 108echo "Done"; 109?> 110--EXPECTF-- 111*** Testing mb_encode_mimeheader() : usage variations *** 112 113-- Iteration 1 -- 114string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 115 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 116 117-- Iteration 2 -- 118string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 119 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 120 121-- Iteration 3 -- 122string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 123 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 124 125-- Iteration 4 -- 126string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 127 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 128 129-- Iteration 5 -- 130string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66?= 131 =?UTF-8?B?zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 132 133-- Iteration 6 -- 134string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 135 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 136 137-- Iteration 7 -- 138string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 139 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 140 141-- Iteration 8 -- 142string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 143 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 144 145-- Iteration 9 -- 146string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 147 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 148 149-- Iteration 10 -- 150string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 151 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 152 153-- Iteration 11 -- 154string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 155 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 156 157-- Iteration 12 -- 158string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 159 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 160 161-- Iteration 13 -- 162string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 163 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 164 165-- Iteration 14 -- 166string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 167 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 168 169-- Iteration 15 -- 170string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 171 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 172 173-- Iteration 16 -- 174 175Warning: mb_encode_mimeheader() expects parameter 5 to be long, string given in %s on line %d 176NULL 177 178-- Iteration 17 -- 179 180Warning: mb_encode_mimeheader() expects parameter 5 to be long, string given in %s on line %d 181NULL 182 183-- Iteration 18 -- 184 185Warning: mb_encode_mimeheader() expects parameter 5 to be long, string given in %s on line %d 186NULL 187 188-- Iteration 19 -- 189 190Warning: mb_encode_mimeheader() expects parameter 5 to be long, string given in %s on line %d 191NULL 192 193-- Iteration 20 -- 194 195Warning: mb_encode_mimeheader() expects parameter 5 to be long, string given in %s on line %d 196NULL 197 198-- Iteration 21 -- 199 200Warning: mb_encode_mimeheader() expects parameter 5 to be long, object given in %s on line %d 201NULL 202 203-- Iteration 22 -- 204string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 205 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 206 207-- Iteration 23 -- 208string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= 209 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?=" 210 211-- Iteration 24 -- 212 213Warning: mb_encode_mimeheader() expects parameter 5 to be long, resource given in %s on line %d 214NULL 215Done 216