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
2 answers

Performance wise String Matching

I've a generic DB query function that runs the following checks every time an SQL query is issued: if (preg_match('~^(?:UPDATE|DELETE)~i', $query) === 1) if (preg_match('~^(?:UPDATE|DELETE)~iS', $query) === 1) if ((stripos($query, 'UPDATE') === 0)…
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
4
votes
2 answers

Wildcards in php's strpos function

I'm looking for some wildcards to the strpos function similar to those used in preg_replace or preg_match but I can't find any, here is an idea:
Rolige
  • 993
  • 8
  • 10
4
votes
6 answers

Check if string contains one of several words

I am trying to make a word filter in php, and I have come across a previous Stackoverlow post that mentions the following to check to see if a string contains certain words. What I want to do is adapt this so that it checks for various different…
Iain Simpson
  • 8,011
  • 13
  • 47
  • 66
4
votes
2 answers

strpos() returning false, when needle is in haystack

I was having trouble with a longer func i wrote, so i broke it down and it seems to be with the strpos() function. Even though the needle is clearly present in the haystack it returns false, for the life of me i cant work out why, oddly though if i…
sam
  • 9,486
  • 36
  • 109
  • 160
4
votes
3 answers

String slicing / string manipulation in PHP

Total accesses: 296282 - Total Traffic: 1.2 GB CPU Usage: u757.94 s165.33 cu0 cs0 - 2.56% CPU load 8.22 requests/sec - 33.5 kB/second - 4175 B/request 22 requests currently being processed, 26 idle workers Let say we have the above as string and we…
lidongghon
  • 323
  • 3
  • 14
4
votes
3 answers

Problem with Strpos In PHP

I'm writing a simple function and for some reason(probably a simple one) it's not working for me and I was wondering if you guys could help me out. function check_value($postID) { $ID = $postID; $cookie =…
Paul Sheldrake
  • 7,505
  • 10
  • 38
  • 50
3
votes
1 answer

How to get strpos in PHP to match foreign language characters?

According to my sources who speak Spanish, if I am searching for the pattern "pan" in a list of strings which contains both these values: $normalString = "abcpan123"; $specialString = "abcpañ123"; it should match both of them -- e.g. strpos("pan",…
tristan
  • 91
  • 4
3
votes
3 answers

PHP: Search in textfile after specific phrases / words and output

I’m trying to make a small php script to automate some work processes. What the script has to do is read a file (approximately 10-20kb per file). Then I need to search the file for some specific phrases and output – if the phrases occur – the…
Emil Devantie Brockdorff
  • 4,724
  • 12
  • 59
  • 76
3
votes
3 answers

How to Find Next String After the Needle Using Strpos()

I'm using PHP strpos() to find a needle in a paragraph of text. I'm struggling with how to find the next word after the needle is found. For example, consider the following paragraph. $description = "Hello, this is a test paragraph. The SCREENSHOT…
scottystang
  • 351
  • 6
  • 22
3
votes
8 answers

Extract first number(s) from variable

I have variables that always start with a number or numbers and need the script to determine where this number ends, now for an example the variable can be like the following: 1234-hello1.jpg 1 hello1.gif 1234hello1.gif 123456 hello1.gif What I am…
Peter Bennett
  • 184
  • 1
  • 2
  • 15
3
votes
2 answers

php strpos not returning any value

So, my website is getting a significant amount of spam. To filter out some of it, I wanted to test the body of the post to make sure it doesn't contain certain words. If they do, give the user an instant (temporary) ban. Included is my code. I…
Dan Smith
  • 533
  • 1
  • 6
  • 15
3
votes
2 answers

Facebook fql case insensitive version of strpos

What is the case insensitive version of strpos(field', 'Phrase') in facebook query language?
Lukasz
  • 19,816
  • 17
  • 83
  • 139
3
votes
2 answers

substring in php whether words is first or last in string

I have this piece of PHP to find a campaign name in string and then use substr on the occurrence of the campaign name. $chars = array("æ", "ø", "å"); $replace = array("ae", "oe", "aa"); $dash = strpos(utf8_decode($campaign["campaign_name"]),…
Morten Hagh
  • 2,055
  • 8
  • 34
  • 66
3
votes
3 answers

search string with html tags

I have html content in PHP variable and I want to search for particular string with it's tags. suppose my variable is $var = "Hi.. howare you? Now I want to search for how in $var then it should return me with…
user3886556
  • 239
  • 3
  • 13
3
votes
5 answers

PHP removing several things from a string at once

I have a string like this being entered into my database that I can't format before it gets stored : image/upload/v1440427262/hglz466d8mm1pazysaoh.jpg#32e2e9a111a4f9f4aa01dbad2ca2aa403c994d28 The only part of that string that I want to use is this…
Grant
  • 1,297
  • 2
  • 16
  • 39