strpos
-
To find the position of a substring within a string of characters, we can use Ruby’s
String#indexmethod.PHP
print strpos("hello world", "wo"); // => 6
Ruby
p "hello world".index("wo") # => 6
The
strposfunction is often used to simply check for the presence of a substring within a string. This is usage is accomplished in Ruby by using theString#include?method.PHP
$result = (strpos("hello world", "wo") !== false); var_export($result); // => true
Ruby
puts "hello world".include?("wo") # => true
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

