1--TEST-- 2Test strcspn() function : usage variations - with varying start and default len args 3--FILE-- 4<?php 5/* 6* Testing strcspn() : with varying start and default len arguments 7*/ 8 9echo "*** Testing strcspn() : with different start and default len values ***\n"; 10 11// initialing required variables 12// initialing required variables 13$strings = array( 14 "", 15 '', 16 "\n", 17 '\n', 18 "hello\tworld\nhello\nworld\n", 19 'hello\tworld\nhello\nworld\n', 20 "1234hello45world\t123", 21 '1234hello45world\t123', 22 "hello\0world\012", 23 'hello\0world\012', 24 chr(0).chr(0), 25 chr(0)."hello\0world".chr(0), 26 chr(0).'hello\0world'.chr(0), 27 "hello".chr(0)."world", 28 'hello'.chr(0).'world', 29 "hello\0\100\xaaaworld", 30 'hello\0\100\xaaaworld' 31 ); 32 33// defining array of mask strings 34$mask_array = array( 35 "", 36 '', 37 "\n\trsti \l", 38 '\n\trsti \l', 39 "\t", 40 "t\ ", 41 '\t', 42 "\t\ ", 43 " \t", 44 "\t\i\100\xa" 45 ); 46 47//defining array of start values 48$start_array = array( 49 0, 50 1, 51 2, 52 -1, 53 -2, 54 2147483647, // max positive integer 55 -2147483648, // min negative integer 56 ); 57 58 59// loop through each element of the arrays for str,mask and start arguments 60$count = 1; 61foreach($strings as $str) { 62 echo "\n-- Iteration $count --\n"; 63 foreach($mask_array as $mask) { 64 foreach($start_array as $start) { 65 var_dump( strcspn($str,$mask,$start) ); 66 } 67 } 68 $count++; 69} 70 71echo "Done" 72?> 73--EXPECT-- 74*** Testing strcspn() : with different start and default len values *** 75 76-- Iteration 1 -- 77int(0) 78int(0) 79int(0) 80int(0) 81int(0) 82int(0) 83int(0) 84int(0) 85int(0) 86int(0) 87int(0) 88int(0) 89int(0) 90int(0) 91int(0) 92int(0) 93int(0) 94int(0) 95int(0) 96int(0) 97int(0) 98int(0) 99int(0) 100int(0) 101int(0) 102int(0) 103int(0) 104int(0) 105int(0) 106int(0) 107int(0) 108int(0) 109int(0) 110int(0) 111int(0) 112int(0) 113int(0) 114int(0) 115int(0) 116int(0) 117int(0) 118int(0) 119int(0) 120int(0) 121int(0) 122int(0) 123int(0) 124int(0) 125int(0) 126int(0) 127int(0) 128int(0) 129int(0) 130int(0) 131int(0) 132int(0) 133int(0) 134int(0) 135int(0) 136int(0) 137int(0) 138int(0) 139int(0) 140int(0) 141int(0) 142int(0) 143int(0) 144int(0) 145int(0) 146int(0) 147 148-- Iteration 2 -- 149int(0) 150int(0) 151int(0) 152int(0) 153int(0) 154int(0) 155int(0) 156int(0) 157int(0) 158int(0) 159int(0) 160int(0) 161int(0) 162int(0) 163int(0) 164int(0) 165int(0) 166int(0) 167int(0) 168int(0) 169int(0) 170int(0) 171int(0) 172int(0) 173int(0) 174int(0) 175int(0) 176int(0) 177int(0) 178int(0) 179int(0) 180int(0) 181int(0) 182int(0) 183int(0) 184int(0) 185int(0) 186int(0) 187int(0) 188int(0) 189int(0) 190int(0) 191int(0) 192int(0) 193int(0) 194int(0) 195int(0) 196int(0) 197int(0) 198int(0) 199int(0) 200int(0) 201int(0) 202int(0) 203int(0) 204int(0) 205int(0) 206int(0) 207int(0) 208int(0) 209int(0) 210int(0) 211int(0) 212int(0) 213int(0) 214int(0) 215int(0) 216int(0) 217int(0) 218int(0) 219 220-- Iteration 3 -- 221int(1) 222int(0) 223int(0) 224int(1) 225int(1) 226int(0) 227int(1) 228int(1) 229int(0) 230int(0) 231int(1) 232int(1) 233int(0) 234int(1) 235int(0) 236int(0) 237int(0) 238int(0) 239int(0) 240int(0) 241int(0) 242int(1) 243int(0) 244int(0) 245int(1) 246int(1) 247int(0) 248int(1) 249int(1) 250int(0) 251int(0) 252int(1) 253int(1) 254int(0) 255int(1) 256int(1) 257int(0) 258int(0) 259int(1) 260int(1) 261int(0) 262int(1) 263int(1) 264int(0) 265int(0) 266int(1) 267int(1) 268int(0) 269int(1) 270int(1) 271int(0) 272int(0) 273int(1) 274int(1) 275int(0) 276int(1) 277int(1) 278int(0) 279int(0) 280int(1) 281int(1) 282int(0) 283int(1) 284int(0) 285int(0) 286int(0) 287int(0) 288int(0) 289int(0) 290int(0) 291 292-- Iteration 4 -- 293int(2) 294int(1) 295int(0) 296int(1) 297int(2) 298int(0) 299int(2) 300int(2) 301int(1) 302int(0) 303int(1) 304int(2) 305int(0) 306int(2) 307int(0) 308int(1) 309int(0) 310int(1) 311int(0) 312int(0) 313int(0) 314int(0) 315int(0) 316int(0) 317int(0) 318int(0) 319int(0) 320int(0) 321int(2) 322int(1) 323int(0) 324int(1) 325int(2) 326int(0) 327int(2) 328int(0) 329int(1) 330int(0) 331int(1) 332int(0) 333int(0) 334int(0) 335int(0) 336int(1) 337int(0) 338int(1) 339int(0) 340int(0) 341int(0) 342int(0) 343int(1) 344int(0) 345int(1) 346int(0) 347int(0) 348int(0) 349int(2) 350int(1) 351int(0) 352int(1) 353int(2) 354int(0) 355int(2) 356int(0) 357int(1) 358int(0) 359int(1) 360int(0) 361int(0) 362int(0) 363 364-- Iteration 5 -- 365int(24) 366int(23) 367int(22) 368int(1) 369int(2) 370int(0) 371int(24) 372int(24) 373int(23) 374int(22) 375int(1) 376int(2) 377int(0) 378int(24) 379int(2) 380int(1) 381int(0) 382int(0) 383int(1) 384int(0) 385int(2) 386int(2) 387int(1) 388int(0) 389int(1) 390int(2) 391int(0) 392int(2) 393int(5) 394int(4) 395int(3) 396int(1) 397int(2) 398int(0) 399int(5) 400int(24) 401int(23) 402int(22) 403int(1) 404int(2) 405int(0) 406int(24) 407int(24) 408int(23) 409int(22) 410int(1) 411int(2) 412int(0) 413int(24) 414int(5) 415int(4) 416int(3) 417int(1) 418int(2) 419int(0) 420int(5) 421int(5) 422int(4) 423int(3) 424int(1) 425int(2) 426int(0) 427int(5) 428int(5) 429int(4) 430int(3) 431int(0) 432int(1) 433int(0) 434int(5) 435 436-- Iteration 6 -- 437int(28) 438int(27) 439int(26) 440int(1) 441int(2) 442int(0) 443int(28) 444int(28) 445int(27) 446int(26) 447int(1) 448int(2) 449int(0) 450int(28) 451int(2) 452int(1) 453int(0) 454int(1) 455int(0) 456int(0) 457int(2) 458int(2) 459int(1) 460int(0) 461int(0) 462int(0) 463int(0) 464int(2) 465int(28) 466int(27) 467int(26) 468int(1) 469int(2) 470int(0) 471int(28) 472int(5) 473int(4) 474int(3) 475int(1) 476int(0) 477int(0) 478int(5) 479int(5) 480int(4) 481int(3) 482int(1) 483int(0) 484int(0) 485int(5) 486int(5) 487int(4) 488int(3) 489int(1) 490int(0) 491int(0) 492int(5) 493int(28) 494int(27) 495int(26) 496int(1) 497int(2) 498int(0) 499int(28) 500int(5) 501int(4) 502int(3) 503int(1) 504int(0) 505int(0) 506int(5) 507 508-- Iteration 7 -- 509int(20) 510int(19) 511int(18) 512int(1) 513int(2) 514int(0) 515int(20) 516int(20) 517int(19) 518int(18) 519int(1) 520int(2) 521int(0) 522int(20) 523int(6) 524int(5) 525int(4) 526int(1) 527int(2) 528int(0) 529int(6) 530int(6) 531int(5) 532int(4) 533int(1) 534int(2) 535int(0) 536int(6) 537int(16) 538int(15) 539int(14) 540int(1) 541int(2) 542int(0) 543int(16) 544int(20) 545int(19) 546int(18) 547int(1) 548int(2) 549int(0) 550int(20) 551int(20) 552int(19) 553int(18) 554int(1) 555int(2) 556int(0) 557int(20) 558int(16) 559int(15) 560int(14) 561int(1) 562int(2) 563int(0) 564int(16) 565int(16) 566int(15) 567int(14) 568int(1) 569int(2) 570int(0) 571int(16) 572int(16) 573int(15) 574int(14) 575int(1) 576int(2) 577int(0) 578int(16) 579 580-- Iteration 8 -- 581int(21) 582int(20) 583int(19) 584int(1) 585int(2) 586int(0) 587int(21) 588int(21) 589int(20) 590int(19) 591int(1) 592int(2) 593int(0) 594int(21) 595int(6) 596int(5) 597int(4) 598int(1) 599int(2) 600int(0) 601int(6) 602int(6) 603int(5) 604int(4) 605int(1) 606int(2) 607int(0) 608int(6) 609int(21) 610int(20) 611int(19) 612int(1) 613int(2) 614int(0) 615int(21) 616int(16) 617int(15) 618int(14) 619int(1) 620int(2) 621int(0) 622int(16) 623int(16) 624int(15) 625int(14) 626int(1) 627int(2) 628int(0) 629int(16) 630int(16) 631int(15) 632int(14) 633int(1) 634int(2) 635int(0) 636int(16) 637int(21) 638int(20) 639int(19) 640int(1) 641int(2) 642int(0) 643int(21) 644int(16) 645int(15) 646int(14) 647int(1) 648int(2) 649int(0) 650int(16) 651 652-- Iteration 9 -- 653int(5) 654int(4) 655int(3) 656int(1) 657int(2) 658int(0) 659int(5) 660int(5) 661int(4) 662int(3) 663int(1) 664int(2) 665int(0) 666int(5) 667int(2) 668int(1) 669int(0) 670int(0) 671int(1) 672int(0) 673int(2) 674int(2) 675int(1) 676int(0) 677int(1) 678int(2) 679int(0) 680int(2) 681int(12) 682int(11) 683int(10) 684int(1) 685int(2) 686int(0) 687int(12) 688int(12) 689int(11) 690int(10) 691int(1) 692int(2) 693int(0) 694int(12) 695int(12) 696int(11) 697int(10) 698int(1) 699int(2) 700int(0) 701int(12) 702int(12) 703int(11) 704int(10) 705int(1) 706int(2) 707int(0) 708int(12) 709int(12) 710int(11) 711int(10) 712int(1) 713int(2) 714int(0) 715int(12) 716int(11) 717int(10) 718int(9) 719int(0) 720int(1) 721int(0) 722int(11) 723 724-- Iteration 10 -- 725int(16) 726int(15) 727int(14) 728int(1) 729int(2) 730int(0) 731int(16) 732int(16) 733int(15) 734int(14) 735int(1) 736int(2) 737int(0) 738int(16) 739int(2) 740int(1) 741int(0) 742int(1) 743int(2) 744int(0) 745int(2) 746int(2) 747int(1) 748int(0) 749int(1) 750int(2) 751int(0) 752int(2) 753int(16) 754int(15) 755int(14) 756int(1) 757int(2) 758int(0) 759int(16) 760int(5) 761int(4) 762int(3) 763int(1) 764int(2) 765int(0) 766int(5) 767int(5) 768int(4) 769int(3) 770int(1) 771int(2) 772int(0) 773int(5) 774int(5) 775int(4) 776int(3) 777int(1) 778int(2) 779int(0) 780int(5) 781int(16) 782int(15) 783int(14) 784int(1) 785int(2) 786int(0) 787int(16) 788int(5) 789int(4) 790int(3) 791int(1) 792int(2) 793int(0) 794int(5) 795 796-- Iteration 11 -- 797int(0) 798int(0) 799int(0) 800int(0) 801int(0) 802int(0) 803int(0) 804int(0) 805int(0) 806int(0) 807int(0) 808int(0) 809int(0) 810int(0) 811int(2) 812int(1) 813int(0) 814int(1) 815int(2) 816int(0) 817int(2) 818int(2) 819int(1) 820int(0) 821int(1) 822int(2) 823int(0) 824int(2) 825int(2) 826int(1) 827int(0) 828int(1) 829int(2) 830int(0) 831int(2) 832int(2) 833int(1) 834int(0) 835int(1) 836int(2) 837int(0) 838int(2) 839int(2) 840int(1) 841int(0) 842int(1) 843int(2) 844int(0) 845int(2) 846int(2) 847int(1) 848int(0) 849int(1) 850int(2) 851int(0) 852int(2) 853int(2) 854int(1) 855int(0) 856int(1) 857int(2) 858int(0) 859int(2) 860int(2) 861int(1) 862int(0) 863int(1) 864int(2) 865int(0) 866int(2) 867 868-- Iteration 12 -- 869int(0) 870int(5) 871int(4) 872int(0) 873int(1) 874int(0) 875int(0) 876int(0) 877int(5) 878int(4) 879int(0) 880int(1) 881int(0) 882int(0) 883int(3) 884int(2) 885int(1) 886int(1) 887int(2) 888int(0) 889int(3) 890int(3) 891int(2) 892int(1) 893int(1) 894int(2) 895int(0) 896int(3) 897int(13) 898int(12) 899int(11) 900int(1) 901int(2) 902int(0) 903int(13) 904int(13) 905int(12) 906int(11) 907int(1) 908int(2) 909int(0) 910int(13) 911int(13) 912int(12) 913int(11) 914int(1) 915int(2) 916int(0) 917int(13) 918int(13) 919int(12) 920int(11) 921int(1) 922int(2) 923int(0) 924int(13) 925int(13) 926int(12) 927int(11) 928int(1) 929int(2) 930int(0) 931int(13) 932int(13) 933int(12) 934int(11) 935int(1) 936int(2) 937int(0) 938int(13) 939 940-- Iteration 13 -- 941int(0) 942int(12) 943int(11) 944int(0) 945int(1) 946int(0) 947int(0) 948int(0) 949int(12) 950int(11) 951int(0) 952int(1) 953int(0) 954int(0) 955int(3) 956int(2) 957int(1) 958int(1) 959int(2) 960int(0) 961int(3) 962int(3) 963int(2) 964int(1) 965int(1) 966int(2) 967int(0) 968int(3) 969int(14) 970int(13) 971int(12) 972int(1) 973int(2) 974int(0) 975int(14) 976int(6) 977int(5) 978int(4) 979int(1) 980int(2) 981int(0) 982int(6) 983int(6) 984int(5) 985int(4) 986int(1) 987int(2) 988int(0) 989int(6) 990int(6) 991int(5) 992int(4) 993int(1) 994int(2) 995int(0) 996int(6) 997int(14) 998int(13) 999int(12) 1000int(1) 1001int(2) 1002int(0) 1003int(14) 1004int(6) 1005int(5) 1006int(4) 1007int(1) 1008int(2) 1009int(0) 1010int(6) 1011 1012-- Iteration 14 -- 1013int(5) 1014int(4) 1015int(3) 1016int(1) 1017int(2) 1018int(0) 1019int(5) 1020int(5) 1021int(4) 1022int(3) 1023int(1) 1024int(2) 1025int(0) 1026int(5) 1027int(2) 1028int(1) 1029int(0) 1030int(1) 1031int(0) 1032int(0) 1033int(2) 1034int(2) 1035int(1) 1036int(0) 1037int(1) 1038int(0) 1039int(0) 1040int(2) 1041int(11) 1042int(10) 1043int(9) 1044int(1) 1045int(2) 1046int(0) 1047int(11) 1048int(11) 1049int(10) 1050int(9) 1051int(1) 1052int(2) 1053int(0) 1054int(11) 1055int(11) 1056int(10) 1057int(9) 1058int(1) 1059int(2) 1060int(0) 1061int(11) 1062int(11) 1063int(10) 1064int(9) 1065int(1) 1066int(2) 1067int(0) 1068int(11) 1069int(11) 1070int(10) 1071int(9) 1072int(1) 1073int(2) 1074int(0) 1075int(11) 1076int(11) 1077int(10) 1078int(9) 1079int(1) 1080int(2) 1081int(0) 1082int(11) 1083 1084-- Iteration 15 -- 1085int(5) 1086int(4) 1087int(3) 1088int(1) 1089int(2) 1090int(0) 1091int(5) 1092int(5) 1093int(4) 1094int(3) 1095int(1) 1096int(2) 1097int(0) 1098int(5) 1099int(2) 1100int(1) 1101int(0) 1102int(1) 1103int(0) 1104int(0) 1105int(2) 1106int(2) 1107int(1) 1108int(0) 1109int(1) 1110int(0) 1111int(0) 1112int(2) 1113int(11) 1114int(10) 1115int(9) 1116int(1) 1117int(2) 1118int(0) 1119int(11) 1120int(11) 1121int(10) 1122int(9) 1123int(1) 1124int(2) 1125int(0) 1126int(11) 1127int(11) 1128int(10) 1129int(9) 1130int(1) 1131int(2) 1132int(0) 1133int(11) 1134int(11) 1135int(10) 1136int(9) 1137int(1) 1138int(2) 1139int(0) 1140int(11) 1141int(11) 1142int(10) 1143int(9) 1144int(1) 1145int(2) 1146int(0) 1147int(11) 1148int(11) 1149int(10) 1150int(9) 1151int(1) 1152int(2) 1153int(0) 1154int(11) 1155 1156-- Iteration 16 -- 1157int(5) 1158int(4) 1159int(3) 1160int(1) 1161int(2) 1162int(0) 1163int(5) 1164int(5) 1165int(4) 1166int(3) 1167int(1) 1168int(2) 1169int(0) 1170int(5) 1171int(2) 1172int(1) 1173int(0) 1174int(1) 1175int(0) 1176int(0) 1177int(2) 1178int(2) 1179int(1) 1180int(0) 1181int(1) 1182int(0) 1183int(0) 1184int(2) 1185int(14) 1186int(13) 1187int(12) 1188int(1) 1189int(2) 1190int(0) 1191int(14) 1192int(14) 1193int(13) 1194int(12) 1195int(1) 1196int(2) 1197int(0) 1198int(14) 1199int(14) 1200int(13) 1201int(12) 1202int(1) 1203int(2) 1204int(0) 1205int(14) 1206int(14) 1207int(13) 1208int(12) 1209int(1) 1210int(2) 1211int(0) 1212int(14) 1213int(14) 1214int(13) 1215int(12) 1216int(1) 1217int(2) 1218int(0) 1219int(14) 1220int(6) 1221int(5) 1222int(4) 1223int(1) 1224int(2) 1225int(0) 1226int(6) 1227 1228-- Iteration 17 -- 1229int(21) 1230int(20) 1231int(19) 1232int(1) 1233int(2) 1234int(0) 1235int(21) 1236int(21) 1237int(20) 1238int(19) 1239int(1) 1240int(2) 1241int(0) 1242int(21) 1243int(2) 1244int(1) 1245int(0) 1246int(1) 1247int(0) 1248int(0) 1249int(2) 1250int(2) 1251int(1) 1252int(0) 1253int(1) 1254int(0) 1255int(0) 1256int(2) 1257int(21) 1258int(20) 1259int(19) 1260int(1) 1261int(2) 1262int(0) 1263int(21) 1264int(5) 1265int(4) 1266int(3) 1267int(1) 1268int(2) 1269int(0) 1270int(5) 1271int(5) 1272int(4) 1273int(3) 1274int(1) 1275int(2) 1276int(0) 1277int(5) 1278int(5) 1279int(4) 1280int(3) 1281int(1) 1282int(2) 1283int(0) 1284int(5) 1285int(21) 1286int(20) 1287int(19) 1288int(1) 1289int(2) 1290int(0) 1291int(21) 1292int(5) 1293int(4) 1294int(3) 1295int(1) 1296int(2) 1297int(0) 1298int(5) 1299Done 1300