phpjs
Version:
285 lines (207 loc) • 8.95 kB
HTML
<!-- Generated by Rakefile:build -->
<strong>
JaypeeHuda
</strong>
on 2011-09-30 11:26:34 <br />
Hello Everyone,
The strpos() function is used to search for a character/text within a string. i.e. with the help of strpos() function you can search a specific character or specific text string. If match is found, strops() function will returns character position of first match. If no match is found, it will return false (Nothing to display).............................. for more details please check out following link...
http://mindstick.com/Articles/4550476c-822d-4506-b41f-edf5ec8228a7/?PHP%20String%20function
thanks !!!!
<hr />
<strong>
<a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
</strong>
on 2011-06-21 18:59:53 <br />
@kirk bushell: Please read the second question on our FAQ: https://github.com/kvz/phpjs/wiki/FAQ about use of JavaScript.
<hr />
<strong>
<a href="http://www.kirkbushell.com" rel="nofollow">kirk bushell</a>
</strong>
on 2011-06-21 09:11:35 <br />
I don't understand the need for a library like this - why not simply learn the language and learn the functions that are available rather than holding onto a language that you love? By learning you become a better developer, rather than writing wrappers for problems that don't exist.
<hr />
<strong>
ELIANE
</strong>
on 2011-03-16 20:33:11 <br />
TENHO MINHA SENHA MAIS NÃO CONSIGO ENTRAR NO MEU HOTMAIL
<hr />
<strong>
<a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
</strong>
on 2010-09-08 17:48:05 <br />
@ Sly: Thanks for helping Chris make sense of this : )
<hr />
<strong>
<a href="http://ncorp.hu" rel="nofollow">Sly</a>
</strong>
on 2010-08-08 09:55:33 <br />
In the example there is a "5":
<pre><code>
strpos('Kevin van Zonneveld', 'e', 5);
</code></pre>
If you see, it means, fnc strpos will search for 'e' after the 5th position of haystack string. Try the example with 0. ;) Like this:
<pre><code>
strpos('Kevin van Zonneveld', 'e', 0);
</code></pre>
>>>>>I really don't understand why you think this works - even your example isn't correct. Find the first occurence of 'e' in 'Kevin van Zonneveld', and you think the answer should be 14? Hmm what about the 'e' in 'Kevin', the first word, and the second letter??
Try to find 'v' and it will come back with 6, missing the 'v' in 'Kevin' once more.
<hr />
<strong>
<a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
</strong>
on 2010-06-02 11:19:03 <br />
@Eugene: indexOf does not work in IE arrays, but it does exist on strings in IE...
<hr />
<strong>
Eugene
</strong>
on 2010-06-01 16:58:08 <br />
indexOf is not working in IE
<hr />
<strong>
<a href="http://chupakabr.ru" rel="nofollow">myltik</a>
</strong>
on 2010-04-15 14:05:31 <br />
thanks for script , works fine for me :-)
<hr />
<strong>
<a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
</strong>
on 2010-03-26 06:55:42 <br />
@Chris: Try dropping the third argument (or setting it to 0) which sets a starting point. It is working correctly...
<hr />
<strong>
Chris
</strong>
on 2010-03-25 16:25:24 <br />
I really don't understand why you think this works - even your example isn't correct. Find the first occurence of 'e' in 'Kevin van Zonneveld', and you think the answer should be 14? Hmm what about the 'e' in 'Kevin', the first word, and the second letter??
Try to find 'v' and it will come back with 6, missing the 'v' in 'Kevin' once more.
<hr />
<strong>
<a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a>
</strong>
on 2009-04-30 04:03:45 <br />
@ Khurram Adeeb Noorani: Also note that the PHP functions have some extra functionality (e.g,. str_replace() can be used with arrays) or extra arguments (like strpos's offset). Besides, for those only familiar with PHP, they can fall back on the PHP names as need be.
<hr />
<strong>
<a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
</strong>
on 2009-04-29 15:29:10 <br />
@ Khurram Adeeb Noorani: Other people do like that. But that's ok. Just compile your own version without the 'duplicate' functions!
<hr />
<strong>
<a href="www.visualcv.com/kanoorani" rel="nofollow">Khurram Adeeb Noorani</a>
</strong>
on 2009-04-29 07:46:45 <br />
Hi,
Thanks for the wonderful functions, they helped me a lot ... Bu what I think is that we need only those functions that are not available in javascript, there is no need of strpos(), explode(), substr() etc, as they are already available in javascript as indexOf() and split() and substr()
<hr />
<strong>
anonymous
</strong>
on 2009-01-20 02:24:19 <br />
<pre><code>
your_stuff('ghatiya');
</code></pre>
<hr />
<strong>
<a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a>
</strong>
on 2009-01-20 02:16:36 <br />
Argh... Sorry, I meant to say that this would be executed in your example:
<pre><code>if (strpos(&quot;ABCand.so.on&quot;, &quot;ABC&quot;) === 0)</code></pre>
but this would not
<pre><code>if (strpos(&quot;ABCand.so.on&quot;, &quot;ABC&quot;) === false)</code></pre>
<hr />
<strong>
<a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a>
</strong>
on 2009-01-20 02:14:07 <br />
@mb : It does work with your example. You just have to keep in mind that because the index position (array indexes start at 0) in your case is '0', it will return 0, so you cannot use it as a boolean like:
<pre><code>if (strpos(&quot;ABCand.so.on&quot;, &quot;ABC&quot;))</code></pre>
because that will indeed not be executed.
If you ran into this problem, the solution is to do this in your code:
<pre><code>if (strpos(&quot;ABCand.so.on&quot;, &quot;ABC&quot;) === false)</code></pre>
which will be executed
<hr />
<strong>
mb
</strong>
on 2009-01-19 16:37:31 <br />
I've noticed that this function does not find for example &quot;ABC&quot; in &quot;ABCand.so.on&quot;.
Bug: if first char of needle is first char of haystack, this does not work.
<hr />
<strong>
<a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
</strong>
on 2008-10-06 12:07:34 <br />
@ Onno Marsman: Good job!
<hr />
<strong>
Onno Marsman
</strong>
on 2008-10-04 17:25:34 <br />
Improved to accept things other than strings like in PHP, and a little optimiztion in the return line ( I used === instead of &gt;=)
<pre><code>
function strpos( haystack, needle, offset){
var i = (haystack+'').indexOf( needle, offset );
return i===-1 ? false : i;
}
</code></pre>
<hr />
<strong>
<a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
</strong>
on 2008-09-13 15:28:44 <br />
@ steve: Well it would be nice if you can copy-paste generic PHP code into a .JS file, and it still works. Straying from the PHP path, means developers have yet another variable to keep track of.. Does this function behave differently from the original PHP function, just because PHP.JS developers think they're smarter?
So we've chosen to stick with PHP and duplicate all of it's features.. and even flaws.
<hr />
<strong>
steve
</strong>
on 2008-09-09 20:19:10 <br />
ok, here's where I get real lost.
I get the point about trying to port the functions - fine.
but strpos()?
this function in PHP has a HORRIBLE bug where it sometimes returns an int, and sometimes a boolean, and worse yet if the string you want is at the zero index, what do you test for?
In JavaScript, all string objects have a .indexOf() and a .lastIndexOf() function that work (IMHO) better than the PHP one, in fact I've seen many libs mimic the JS behavior in a PHP version of index_of()
JS .indexOf()
returns the (zero based index as an integer (if found))
else
returns the integer -1 (e.g. not found)
This works much better as you can have logic like.
<pre><code>
if(someString.indexOf('secretcode')){
//do your magic
}
</code></pre>
if you *need* the offset option, you can accomplish with:
<pre><code>
function index_of(haystack, needle, offset){
if(offset){
haystack = haystack.substr(offset);
}
return haystack.indexOf(needle);
}
</code></pre>
Then again, maybe I'm missing the point of this exercise?
<hr />
<strong>
<a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
</strong>
on 2008-09-08 00:16:22 <br />
I would still learn JS if I was you.. Don't miss out on beautiful things like jQuery. PHP.JS is just a tool to smoothen up the edges between client &lt;&gt; server interaction development.
<hr />
<strong>
<a href="weareinto.com" rel="nofollow">Kirk Strobeck</a>
</strong>
on 2008-09-06 00:43:42 <br />
This is great. Just what I needed. This small conversion basically means you don't need to learn JavaScript if you know PHP. Nice.
<hr />
<strong>
oooooooooooo
</strong>
on 2008-08-25 18:47:38 <br />
Thank you!
<hr />