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
-4
votes
1 answer

How to use strpos in PHP 7.3 or higher

I have to use php 7.3.x for a website, but I have a file that uses the strpos function. Is there a solution to use this function or is there a replacement in php 7 for this function? this is my code if(strpos($text, $data['word']) !== false) { …
Top30k
  • 1
-4
votes
3 answers

remove part of string after a special character

What I am trying to do is remove a * and the number after it from a string. $string = 'something*10'; $string2 = 'something*1'; needs to output something something not something*10 something*1
Jayden
  • 437
  • 2
  • 7
  • 11
-4
votes
3 answers

How to get position of last character in a string?

For example, I have $string = "abc+def", how can i get position of 'f'? Is it possible of finding position of last character in the string, in the above example, 'f' is last character.
-4
votes
2 answers

strpos() Returning wrong result

My issue is I have two numbers in the array 5,12 my issue is the code below is returning "1" as true because of the "1" in number 12- it sees the number 1 in 12. How do I tell it to read the ENTIRE number.
-4
votes
4 answers

Unable to find position of the first occurrence in a string

I need to find position of the first character occurrence in a string that does not repeat. So far all I have my $pos outputs 0.
crashtestxxx
  • 1,405
  • 5
  • 21
  • 30
-5
votes
1 answer

Warning: strpos(): Empty needle in /XXX/post.php on line XXXX

I have such a prolem since I had to change the server provider. I was porting a few wordpress based sites using the Duplicator plugin. Now wherever in the content of the page I use the tag, it returns an error Warning: strpos(): Empty needle in…
Tadq
  • 1
-5
votes
1 answer

Split first name and last name with php and search in array

I have a problem. I have a List of thousand names and must split them with php, perhaps with mysql. The Names looks like this: johndoe peterhoward martinsmith mickymaus aaaa I have an list of all possible and valid first names and lastnames. Now I…
Mann87
  • 314
  • 1
  • 4
  • 14
-5
votes
1 answer

PHP strpos not working right

EDIT: Ok for everyone who seems to be mentally disabled or something, check this out how it should be and why Halcyon's solution to swap haystack and needle DO MAKE SENSE: $test = 'bla'; if(strpos($test, 'hauptkat') !== false OR strpos($test, 'kat')…
-6
votes
2 answers

strpos() expects parameter 1 to be string, resource given

I'd like the $description to be a string of words pulled from the Description column. Then I want to check if the string has the $searchterm (one word defined prior to this block of code). //3. (a)for each, (b) if search term is in the description…
Michael
  • 1
  • 1
-7
votes
2 answers

How do search array values and remove them based on a condition or string?

Read the file names from the array. Search the array value for the string "-dep" and if any string value contains "-dep", remove it. Pass the array as as value to another array . for($d=0; $d < $files; ++$d) { if(strpos($files[$d], "-dep") ===…
codename32
  • 171
  • 1
  • 9
1 2 3
48
49