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

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated

We are using the following functions for an Invoice Module: /* Functions: Before */ function before ($here, $inthat){ return substr($inthat, 0, strpos($inthat, $here)); } /* Functions: After */ function after ($here,…
celextel
  • 1
  • 1
  • 1
  • 3
-1
votes
1 answer

PHP - Find opening

tag before a specific string and add a class to it

I have the following piece of text:

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

Lorem Ipsum has been the industry's

standard dummy text

ever since the 1500s

When an unknown printer took a…

odd_duck
  • 3,941
  • 7
  • 43
  • 85
-1
votes
1 answer

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

I have a problem with an old plugin installed on my Wordpress site. Since I updated my php to php 7.4, I am getting the message saying: "Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr()…
-1
votes
2 answers

How to search a string for multiple multi-word phrases in Swift or Objective-C

I want to parse a large number of strings for canned phrases or names and then store the names, if found, in an array where the order counts. So for example, starting with a string such as: str = "The movie stars Robert Duvall and James Earl Jones…
user6631314
  • 1,751
  • 1
  • 13
  • 44
-1
votes
1 answer

Using PHP strpos() function inside and if loop won't work as expected?

I have a string of text that is the name of a file, and I want to show it only if the name of the file does not contain an image extension. This are the string…
Rosamunda
  • 14,620
  • 10
  • 40
  • 70
-1
votes
4 answers

PHP if statement strpos === false with an or ||

I'm trying to get the if statement to echo equals true but it equals false. What am I doing wrong? sometimes $line-2 will be 5% and sometimes it will be 0%. So it varies like that. How would I write the if statement for both cases? So basically, I…
Mike
  • 607
  • 8
  • 30
-1
votes
2 answers

PHP - strpos() with whitespace

imap subject = "code. 115 is your id" I tried using below one but didnt worked. $headerInfo = imap_headerinfo($connection); if (!strpos($headerInfo->subject, "code. $id")) { echo true } $headerInfo = imap_headerinfo($connection); if…
kinger123
  • 1
  • 6
-1
votes
2 answers

PHP 7.0 STRPOS not functioning as expected

So, I was trying to use strpos to test if a string existed in a variable, but in all my attempts to make the if statement work, it was not succeeding, so I went about outputting the string and trying to find the point where strpos detected it, but…
Sean Mitchell
  • 447
  • 2
  • 21
-1
votes
2 answers

How to use conditions on functions like strpos() in PHP?

I wanted to check if a string contains specific words? According How do I check if a string contains a specific word? I can use strpos() function. Sample Code I wrote if(strpos($value, 'filters(10)') === false){ //Do something } else { //Do…
-1
votes
1 answer

PHP Regex expert needed - find text within string but with wildcard

I have code currently that matches $data=["as much as I like oranges, I like bananas better", "there's no rest for the wicked", "the further I move from my target, the further I get", "just because I like that song, does not mean I will buy it"]; …
Hasen
  • 11,710
  • 23
  • 77
  • 135
-1
votes
1 answer

edit to substr and strpos causes Error 500

I'm trying to make some edits to a piece of code but I get an error 500 when I do. For this example, lets say that basename(__FILE__) is my_filename.php The code is: $HTTP_GET_VARS['feed_file'] = $_GET['feed_file'] = substr( …
Steve Price
  • 600
  • 10
  • 28
-1
votes
2 answers

How to check if word exist in a string with php

How can i check if word exist in a string. I tried strpos but not with good results. My example if(strpos($string, 'As ') !== false) And string is : "Asthmatic is ruff" Then it gives me true, as the As is included. But i need to find word "As"…
Gun arves
  • 95
  • 1
  • 7
-1
votes
3 answers

Fnd specific place in string and get data from it

I have string with multiple image tags in it. Like this I want to find FIRST such tag, and get image name from it 5844644f69fe7-64.jpg How can be this done in PHP asuming there is a…
David
  • 4,332
  • 13
  • 54
  • 93
-1
votes
2 answers

strpos not working with $post method

I have a IF Statement where when i submit my page it is going to check if the time exists already and if so assign a value to my variable or echo out a message saying it found the time. Doesnt seem to be working though, i tried == true and !== false…
William
  • 1,009
  • 15
  • 41
-1
votes
1 answer

How to search array for specific word with strpos

$data = " usera: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy. userb: eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam. userc:voluptua. At vero eos et accusam et justo duo dolores et ea rebum.…
Andre
  • 1
  • 1