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