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

php if condition with OR operator not working

I'm trying to check if the the url is win or scholartips when the script gets a hit. conditional script here But whenever i…
windy boy
  • 13
  • 1
  • 1
-2
votes
3 answers

Counting the number of times a substring occurs in a string using strlen+substr+strpos ONLY PHP

I would like to write a function that can count the number of times a substring occurs in a string using strlen+substr+strpos ONLY ,in PHP. Without using substr_count! example: fn('iwritecodeiwritecode-','i'); Thanks Ahead
Pioneer2017
  • 537
  • 2
  • 5
  • 11
-2
votes
2 answers

if statement syntax equal to

I am using Views php in Drupal 6. I need to do an if statement to find if nodehierarchy_parent is equal to the value 0. Then do something. Right now I have it set to if the value contains a 0. My code is below.
paul cappucci
  • 243
  • 1
  • 12
-2
votes
2 answers

Warning: strpos() expects parameter 1 to be string, array given in

I don't know what happen eror_log generate, but code works fine, but log is make me curious PHP Warning: strpos() expects parameter 1 to be string, array given in /home/abc/public_html/url.php on line 46 the line 46 is: if…
astack
  • 37
  • 2
  • 9
-2
votes
1 answer

PHP mb_strpos not recognizing copyright symbol

I am trying to use the mb_strpos PHP function to search for the © symbol on certain webpages. $pagecontent = file_get_contents($website_url); if (mb_strpos($pagecontent, $string_to_find) === false) { // String /…
rosey85uk
  • 95
  • 2
  • 12
-2
votes
3 answers

Remove all zero values from string PHP

I have a string like this: 14522354265300000000000 I want to display it without zero values, how I can do this? I do this $pos = strpos($route, '0'); $length = count(str_split($route)); $a = $length - $pos; $a = substr($route, 0, $a); but it…
nowiko
  • 2,507
  • 6
  • 38
  • 82
-2
votes
1 answer

php strpos doing weird things

I have this code here and for some reason it will accept either the first 3 ifs as true or the last if. I can't seem to get it to go to one or the other without just removing one of them. The input coming in for example is 'TBN D664' or 'Other'…
dup3
  • 3
  • 3
-2
votes
1 answer

Issues with strpos inside while loop

My question is mainly about a "while condition" that apparently returns "TRUE" when in shuld return "FALSE". This is the code:
deotpit
  • 95
  • 1
  • 3
  • 12
-2
votes
1 answer

How to get full substring in a string?

I have variable $mystring = "abc+adb" and I am trying to find ab in the $mystring. I want to throw a message which say ab does not exist in $mystring, but the following code keeps picking ab from abc, I want ab to be treated as a standalone…
-2
votes
1 answer

How to check if a string contains a dot followed by a number in PHP

I am trying to check if a string contains .2. The following code works if I try to check if it contains a dot: strpos($string, '.') !== false But it doesn't work when use the following code: strpos($string, '.2') !== false nor strpos($string,…
Nicolas123
  • 47
  • 1
  • 1
  • 8
-2
votes
1 answer

PHP type juggling with strpos() conditions and ||, in spite of strict ===?

Except for two files (bg177b_s.php and bg177b_t.php) a headline shall be added. In other words, if neither of the two strpos() conditions matches, something shall be done, else nothing. I got this to work two ways, provided that strpos() won't…
JayAitch
  • 175
  • 1
  • 1
  • 10
-2
votes
1 answer

Warning: strpos() [function.strpos]: Empty delimiter on line 70

I am getting an error: Warning: strpos() [function.strpos]: Empty delimiter on line 70 What is the problem? Here is the relevant part of the code: if (strpos($this->request->server['HTTP_USER_AGENT'], trim($rt)) !== false) { Im not an expert on…
Daniel G. Gabori
  • 65
  • 1
  • 2
  • 8
-2
votes
1 answer

strpos: 2 results but 2 similar strings

I don't know what to do. 2 parameters: first: 0 D:/Google Drive/Dokumente/Programmierung/Webentwicklung/htdocs/BeLL__Webseite_fuer_Filmfestival/php/checkSession.php(6): Phip/Engine/Login->checkSession() 1 D:/Google…
phip1611
  • 5,460
  • 4
  • 30
  • 57
-2
votes
3 answers

PHP program related to stringpos() function issue

$text = $_POST['text']; $find = $_POST['find']; $offset = 0; while ($offset < strlen($text)) { $pos = strpos($text, $find, $offset); $offset += strlen($find); echo "$find found in $pos
"; } There is something wrong with this program.…
Eisa Adil
  • 1,743
  • 11
  • 16