Questions tagged [strpos]

PHP method to find the position of the first occurrence of a substring in a string

PHP method to find the position of the first occurrence of a substring in a string

PHP Reference: https://www.php.net/manual/en/function.strpos.php

730 questions
-1
votes
1 answer

find exacly phrase of sentence, not a path of phrase

I have problem with search tool! I use strpos function to search $phrase_key in $sentence, and there are some wrong! strpos($sentence , $phrase_key, 0) $phrase_key = "on the"; $sentence1 = "i am sitting on the table" // Good…
hunghvq
  • 11
  • 3
-1
votes
5 answers

Check if an array element is in a string

This question has been asked before about strings, however *none of the questions I've reviewed (not mods do not remove or tell us this is a duplicate please) actually answer my question. I have a landing page with a simple signup via email box.…
GeordieDave1980
  • 589
  • 4
  • 11
  • 25
-1
votes
2 answers

Error: strpos() [function.strpos]: Empty delimiter

I got this littel problem here with this code
1 2 3
gad
  • 1
  • 3
-1
votes
2 answers

PHP String position handling names with apostrophes

If there is a name in a database (ie. O'Reilly) and I create the insert statement to insert this name into a database via a SQL query in a PHP script, it will cause an error because the apostrophe in the name will end the string and cause the query…
-1
votes
2 answers

Check to see if EXACT value is in a string - PHP

I have read numerous posts about how to see if a value is in a string. Apparently my request is different since the multiple bits of code haven't worked 100%. I am searching a string and need to make sure the EXACT value is in there - with a perfect…
Joey Martin
  • 369
  • 1
  • 3
  • 11
-1
votes
1 answer

Stop Malicious Hacker

Someone keeps posting a large number of vulgar posts to my database. They are usually the same. The only way I can stop them is by breaking the .php page, and then deleting them, and then adding something like the following to the .php post page: …
-1
votes
2 answers

strpos of 0 breaking while loop

So once again I'm practicing PHP. Specifically strpos() in a while loop. The trouble with the below code is that strpos() results in 0 at the first loop, which yields a false result in the while condition, thus terminating the loop. $string = 'orem…
Russ
  • 469
  • 1
  • 7
  • 13
-1
votes
2 answers

strpos - user agent partial matching

I am trying to detect 2 different phones based on their user agents. I used strpos but my code is outputting "other phone" on both phones. $ua = $_SERVER['HTTP_USER_AGENT']; $phone1 = "SM-G900F"; $phone2 =…
Cody Raspien
  • 1,753
  • 5
  • 26
  • 51
-1
votes
1 answer

why can i not find a substring with strpos()?

I'd like to extract a substring within a string but seems like strpos() doesn't fidn my substring. I have the following code: -------------------------
"; …
stdcerr
  • 13,725
  • 25
  • 71
  • 128
-1
votes
2 answers

strpos returns true when using clearly different strings

I'm taking data from an excel using phpexcel, like this: $number = $objPHPExcel->getActiveSheet()->getCell('A3')->getValue(); number is clearly a number, okay? so, after that I want to know if $number exists on the word…
WhiteFloater
  • 137
  • 1
  • 1
  • 10
-1
votes
1 answer

Using php explode to echo some part of a string

I am trying to echo some part of a string, the string is for example: "?page=tournament&action=brackets&tournID=2" I am not using URL so I cannot use $_GET. Only string. I want to get the first and second element after "=" Thus should return $first…
Karim Ali
  • 11
  • 1
-1
votes
1 answer

Look for phrase in string, and also look for wildcards after the phrase

I'm looking for a way to display some code based on the URL of the site. Case 1: If url contains getting-started do something Case 2: If url contains getting-started/* (could be anything) show something else. I'm currently getting the URL string…
Francesca
  • 26,842
  • 28
  • 90
  • 153
-1
votes
1 answer

strpos empty/blank substring in string

I have a string that is attempting to find specific resources within an API call. The resources are levels: undergraduate, graduate, independent academic work, and "" (which supposedly means none/unassigned). So, is simply using strpos($level, "")…
timmyg
  • 181
  • 1
  • 14
-1
votes
2 answers

PHP Warning: strpos

So I have looked everywhere and I couldn't fimd the solution to my problem. I am using steam OpenID, and I keep getting this message: Warning: strpos() [function.strpos]: Offset not contained in string. if(($host_end = strpos($this->trustRoot,…
-1
votes
2 answers

strrpos wont evaluate certain strings

$target is a char and I am trying to find the last occurrence of that char in $line. I get -1 for every single output even if I am certain the $target does exist within $line at some index. $fh = fopen($someFile, "r"); while (!feof($fh)) { …
STLCards77
  • 121
  • 14