Jump to content

Is there any preg function that finds out the position of a word in a string?


ted_chou12

Recommended Posts

yes, i tried this: $pos = preg_split('/ /', $pquery1, -1, PREG_SPLIT_OFFSET_CAPTURE); but what it gives me is the position of each word in relate to the white spaces, however, it doesnt search a specific word, what it does is find out the starting position of each word in the string, and that is not very useful to me at all.

Ted

strpos limits the results, because I am also trying to match results that are case insensitive, so for Test,

test

tesT

teST

...

all of the combinations will match, however, not for strpos.

Ted

strpos limits the results, because I am also trying to match results that are case insensitive, so for

 

So, before you run your comparison, just make a temp string in lowercase to test:

<?php
$word = strtolower($word);
$temp = strtolower($string);
$loc = strpos($temp, $word);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.