phpjs
Version:
186 lines (145 loc) • 4.99 kB
HTML
<!-- Generated by Rakefile:build -->
<strong>
<a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
</strong>
on 2012-09-18 16:12:50 <br />
@Thomas: Fixed in Git, thanks!
<hr />
<strong>
Thomas
</strong>
on 2012-09-18 04:11:49 <br />
var pos = 0 is initialized but never used.
<hr />
<strong>
<a href="http://www.formal-shirts.co.uk/" rel="nofollow">formal shirts</a>
</strong>
on 2012-05-15 10:12:29 <br />
This is s good looping code and is working as it is being told in here. Happy to learn some basics of the coding language.
<hr />
<strong>
<a href="http://www.hotfixrhinestonebeads.com/" rel="nofollow">jimmyfreaky</a>
</strong>
on 2012-05-14 13:37:22 <br />
that was amazing guyz it s very informative code i like it...
<hr />
<strong>
jimmyfreaky
</strong>
on 2012-05-14 13:36:12 <br />
Hot fix rhinestones are the latest beads and fashion accessories, which are very prominent among the ladies, this is the fashion accessory that comes in the range of every woman, and its unique design makes it beautiful and stylish. <a href="http://www.hotfixrhinestonebeads.com/">wholesale hot fix rhinestones</a>
<hr />
<strong>
<a href="http://hedokse.hyves.nl/blog" rel="nofollow">Jeremy</a>
</strong>
on 2012-04-24 19:42:46 <br />
I must say, useful information for users especailly for website designers.
<hr />
<strong>
<a href="http://www.flowers-magzine.com/Spring_Flowers" rel="nofollow">saraanderson</a>
</strong>
on 2012-04-24 08:33:39 <br />
Really your post is really very good and I appreciate it. It’s hard to sort the good from the bad sometimes, but I think you’ve nailed it. You write very well which is amazing. I really impressed by your post.
<hr />
<strong>
<a href="http://an3m1.com/" rel="nofollow">????? ????? ????</a>
</strong>
on 2012-04-18 10:17:38 <br />
This is a very informative article. I was looking for these things and here I found it. I am doing a project and this information is very useful me. Some things in here I have not thought about before
<hr />
<strong>
Rafal
</strong>
on 2011-10-06 15:54:33 <br />
Great!
Świetne, bardzo mi się przydało.
Greetings from Poland - Rafal
<hr />
<strong>
<a href="http://www.xarg.org/" rel="nofollow">Robert Eisele</a>
</strong>
on 2011-09-05 00:04:57 <br />
What about this optimization?
<pre><code>
function substr_count(haystack, needle, offset, length) {
haystack+= "";
needle+= "";
if (isNaN(offset)) {
offset = 0;
}
if (isNaN(length)) {
length = haystack.length - offset;
}
haystack = haystack.substr(offset, length);
return (haystack.length - haystack.replace(new RegExp(needle, 'g'), "").length) / needle.length;
}
</code></pre>
<hr />
<strong>
<a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
</strong>
on 2009-07-24 12:07:57 <br />
@ Shock: I think I would have to make the same point as here:
http://phpjs.org/functions/substr_count:559#comment_626
Don't you agree?
<hr />
<strong>
<a href="http://freecr.ru/" rel="nofollow">Shock</a>
</strong>
on 2009-07-20 01:26:41 <br />
// Maybe something like that?
<pre><code>function substr_count( haystack, needle, offset, length ) {
if (isNaN(offset)) {
offset = 0;
}
if (isNaN(length)) {
length = haystack.length - offset;
}
if (length <= 0 || (length + offset) > haystack) {
return false
} else {
return haystack.substr(offset,length).split(needle).length - 1;
}
}</code></pre>
sorry for doublePost
<hr />
<strong>
<a href="http://freecr.ru/" rel="nofollow">Shock</a>
</strong>
on 2009-07-20 01:25:28 <br />
// Maybe something like that?
<pre><code>function substr_count( haystack, needle, offset, length ) {
if (isNaN(offset)) {
offset = 0;
}
if (isNaN(length)) {
length = haystack.length - offset;
}
if (length <= 0 || (length + offset) > haystack) {
return false
} else {
return haystack.substr(offset,length).split(needle).length - 1;
}
}[/CODE
<hr />
<strong>
<a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
</strong>
on 2009-01-25 13:48:59 <br />
Well we could benchmark it of course. But I think that when your doing this on really large strings, you also end up with really large arrays, that you really don't need. So my guess is that your approach will be more memory intensive don't you agree?
<hr />
<strong>
<a href="http://antimatter15.com" rel="nofollow">antimatter15</a>
</strong>
on 2009-01-18 14:21:35 <br />
Wouldn't it be faster to just use split().length-1?
<pre><code>function substr_count( haystack, needle, offset, length ) {
if(!isNaN(offset)){
if(!isNaN(length)){
haystack=haystack.substr(offset,length);
}else haystack = haystack.substr(offset)
}
haystack = haystack.split(needle).length-1
return haystack&lt;0?false:haystack;
}</code></pre>
<hr />