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

PHP: How to check if ANY are located in string?

I am trying to see if any of a list of items are located in a PHP string. I know how to use strpos to test against one item: if (strpos($string, 'abc') !== FALSE) { But, how would I test, for example, if either 'abc' or 'def' appear in the $string?
MultiDev
  • 10,389
  • 24
  • 81
  • 148
-1
votes
2 answers

PHP foreach and strpos newbie

Why doesn't this work? $statement = array( images_name[0] => 'small_01.jpg', images_name[1] => 'large_01.jpg', ); foreach ($statement->images as $image): if (strpos($image->name, 'small')) { echo ('yes'); } endforeach I can print the…
-1
votes
1 answer

Function to find a string inside another string and then find any numbers after that string in PHP

I'm hoping someone can help me. I would like a PHP function that takes a string (X), and searches it for another string (Y). After Y is found (left to right search), the function will return only numbers found after Y but will not return numbers (or…
jonathanbell
  • 2,507
  • 5
  • 23
  • 40
-1
votes
1 answer

Replace certain text

I have the following code: name == "Price range") { if (strpos($actual_link,'/attr/price_range_') !==…
-1
votes
3 answers

Using strpos, check if given URL has 'any one' of the strings in the array?

I have a variable $url (who I have no control over) whose value is a URL (as a string). For example: $url = 'http://www.youtube.com/watch?v=rSnzy2dZtsE'; I have a list of hosts (example.com) that I'd like to check against the $url, and see if any…
its_me
  • 10,998
  • 25
  • 82
  • 130
-1
votes
3 answers

repeating values?

I'm getting compiling this script which it matches all current word in the array and on the database and print if it's existing in the database. here's the script:
Darline
  • 195
  • 3
  • 13
-1
votes
4 answers

Check if string starts with http or www or /

This works: if (strpos($page, 'http') == 0) { $link = 'Test'; } But this doesn't: if (strpos($page, 'http' || 'www' || '/') == 0) { $link = 'Test'; } I need to return something if $page does not begin with any of those three: http,…
Works for a Living
  • 1,262
  • 2
  • 19
  • 44
-1
votes
1 answer

strpos() function on mysql_fetch_array

i have the code fetching the information from the MySQL database in PHP and then i want to compare $username variable with those information with strpos() function...but it doesn't work.... what can i do? $username = $_GET['username']; $connection…
Pouyan Izadi
  • 19
  • 1
  • 2
-1
votes
1 answer

How to substr or strpos this character

Help me to get this character in one code 4edtee3fdpd0h8o kfz254yae7cw8fb da84s08ifannjs6 a4x4c1eaki9ekw1 From this url : all of this…
-1
votes
1 answer

Obtain the type of archive

I'm trying to obtain the type of archive in php with strops and substr. How can I find the position of the first point from the end of the name of the file? $archive_name=$_FILES['uploaded_file']['name']; $type=substr($archive_name, strpos(".") ) …
-2
votes
2 answers

Remove characters from beginning and end string

I want to ouput only MYID from URL. What I did so far: $url = "https://whatever.expamle.com/display/MYID?out=1234567890?Browser=0?OS=1"; echo substr($url, 0, strpos($url, "?out=")); output: https://whatever.expamle.com/display/MYID $url =…
user16370794
-2
votes
2 answers

Get all occurrences of a string between two delimiters in PHP

I am using a PHP function to get all content between two delimiters in a string. However, if I have multiple occurrences of the string, it only picks up the first one. For example I'll have: |foo| hello |foo| nothing here |foo| world |foo| and the…
awholegnuworld
  • 381
  • 1
  • 12
-2
votes
1 answer

PHP how to add variable string after strpos

I am getting all the data of a webpage then searching it for a certain string. I use strpos to find the location, then once found i would like to create a variable that stores all the information 64 characters past the strpos. E.g: $begin =…
SuperBot12
  • 77
  • 8
-2
votes
1 answer

Contains em PHP in return Regex

I am having difficulty in searching for a specific word in text. I tried to use the stripos method, but it throws an error because the text return is an object: $text = preg_replace("/note:/" ,'' , $text); if(stripos($text, "note:") !== false){ …
-2
votes
2 answers