UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

61 lines (51 loc) 1.95 kB
--- layout: page title: "JavaScript strpbrk function" comments: true sharing: true footer: true alias: - /functions/view/strpbrk:544 - /functions/view/strpbrk - /functions/view/544 - /functions/strpbrk:544 - /functions/544 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's strpbrk {% codeblock strings/strpbrk.js lang:js https://raw.github.com/kvz/phpjs/master/functions/strings/strpbrk.js raw on github %} function strpbrk (haystack, char_list) { // From: http://phpjs.org/functions // + original by: Alfonso Jimenez (http://www.alfonsojimenez.com) // + bugfixed by: Onno Marsman // + revised by: Christoph // + improved by: Brett Zamir (http://brett-zamir.me) // * example 1: strpbrk('This is a Simple text.', 'is'); // * returns 1: 'is is a Simple text.' for (var i = 0, len = haystack.length; i < len; ++i) { if (char_list.indexOf(haystack.charAt(i)) >= 0) { return haystack.slice(i); } } return false; } {% endcodeblock %} - [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/strings/strpbrk.js) Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are the closest match to this hashtable-like data structure. Please also note that php.js offers community built functions and goes by the [McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just: - [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/strings/strpbrk.js) ### Example 1 This code {% codeblock lang:js example %} strpbrk('This is a Simple text.', 'is'); {% endcodeblock %} Should return {% codeblock lang:js returns %} 'is is a Simple text.' {% endcodeblock %} ### Other PHP functions in the strings extension {% render_partial _includes/custom/strings.html %}