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

preg_match VS. stripos in PHP

The target is to check a product description and to identify different characteristics/product options. The input data has the following structure: // TABLE WITH INPUT DATA. STRUCTURE: PRODUCT_CATEGORY [0], PRODUCT_NUMBER[1], DESCRIPTION OF AN…
2
votes
1 answer

Delete string between strings and replace with text plus counter

I want to remove all base64 images from a string ... and replace them with image1, image2 and so on. ... So I am deleting…
user18027792
2
votes
6 answers

Finding words in a string

Can anyone suggest how I would do this: Say if I had the string $text which holds text entered by a user. I want to use an 'if statement' to find if the string contains one of the words $word1 $word2 or $word3 . Then if it doesn't, allow me to run…
Joey Morani
  • 25,431
  • 32
  • 84
  • 131
2
votes
1 answer

Why does php strpos() sometimes does not work on Unicode character?

I'm building a system that categorizes woo-commerce products by their name, my product's name is in Hebrew. I have to check in my code if a name of a product contains a Hebrew word. if I write something like: strpos(hebrev("סט של…
2
votes
4 answers

Foreach strpos problem. Find string in another string

I'm trying to get this script to work. The idea is that if the input string ($query) doesn't start with '/t' AND contains one of the $trigger words, an $error is set. I can't get this to work and I'm not sure why.
Steve Robbins
  • 13,672
  • 12
  • 76
  • 124
2
votes
0 answers

Problems with $_GET variable and strpos

I am trying to find a instance of a string inside another using strpos() but I am having problems. if(strpos($line, $_GET['search']) !== FALSE){ //does not work $line is a single line of a text file read in by fgets() and $_GET['search'] is…
2
votes
4 answers

strpos and string in string searches

I have a comma delimited string and I need to be able to search the string for instances of a given string. I use the following function: function isChecked($haystack, $needle) { $pos = strpos($haystack, $needle); if ($pos === false) { …
bikey77
  • 6,384
  • 20
  • 60
  • 86
2
votes
3 answers

When should I use mb_strpos(); over strpos();?

Huh, looking at all those string functions, sometimes I get confused. One is using all the time mb_ functions, the other - plain ones, so the question is simple... When should I use mb_strpos(); and when should I go with the plain one (strpos();)? …
tomsseisums
  • 13,168
  • 19
  • 83
  • 145
2
votes
1 answer

How I can extract ordered questions and answers from a block of plain text

Questions are also available for plain text. I want to be able to use PHP, Regex. However, because my Regex information is not enough, I tried to do this with the PHP function. Example plain text: (starting 12th question -> 15. question, here total…
Editor
  • 622
  • 1
  • 11
  • 24
2
votes
2 answers

How can I test for a partial string value in an array

So I have a checkbox form that stores values in an array, with several values for each key. How can I test if a value is checked? in_array() isn't returning true for values that are in the array. print_r($array) results: Array ( [auto_loans] =>…
jbro
  • 25
  • 4
2
votes
5 answers

PHP strpos() return empty value

I meet a strange thing with the PHP function strpos(). I have a function that check if a passed string is found in a txt file. I can display the content of the file line by line but the strpos() doesn't return a value (nothing in fact). var_dump()…
Ben
  • 31
  • 2
2
votes
2 answers

Why use iconv_strpos instead of strpos?

In contrast to strpos(), the return value of iconv_strpos() is the number of characters that appear before the needle, rather than the offset in bytes to the position where the needle has been found. (Source:…
flather
  • 165
  • 1
  • 8
2
votes
3 answers

limit result to one in object foreach loop, in_array does not work

I have a list of cities, these cities may exists once or repeated several times, or may not exists at all. With php I want to check if city is in the foreach, and if exists print only one input out. Below works perfect, print city only if exist, but…
Helenp
  • 143
  • 2
  • 15
2
votes
1 answer

PHP word comparison and weighting

I am currently writing a search match for a project I am working on. As part of the search I will use a wide mixture of exact keyword, phrase and other metrics to provide a weighted score for the search results. The aim being to allow comparison of…
Pete - iCalculator
  • 929
  • 1
  • 8
  • 12
2
votes
1 answer

How does this particular StrPos work in PHP?

I have the following code. I'm wondering if it's working like I think it is: //Gift Card Redemption if(strpos($_order->getDiscountDescription(), 'Gift Card') !== false){ $order .=…
James
  • 529
  • 1
  • 7
  • 16