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

Tagging phrases in paragragh

I am using PHP and I am looking to create links within my text to other sections of the site so for example: I fell into the media industry aged 30, when David Mansfield, now on the board of Ingenious Media, gave me my first break at Thames TV. From…
Lizard
  • 43,732
  • 39
  • 106
  • 167
3
votes
1 answer

PHP strpos match all needles in multiple haystacks

I want to check if ALL words from $words exist in one or more $sentences, word order is not important. Words will only contain [a-z0-9]. Sentences will only contain [a-z0-9-]. My code so far, it almost work as expected: $words = array("3d",…
Sunny
  • 207
  • 2
  • 13
3
votes
6 answers

Check if string contains any value of an array?

$search=array("<",">","!=","<=",">=") $value="name >= vivek "; I want to check if $value contains any of the values of the $search array. I can find out using foreach and the strpos function. Without resorting to using foreach, can I still find the…
Vivek Aasaithambi
  • 919
  • 11
  • 23
3
votes
3 answers

In PHP, strpos() fails to find double quote ('"') in string

Both this: echo 'Tok: '.$tok.' Strpos: '.strpos($tok, "\"").' length: '.strlen($tok).'
'; And this: echo 'Tok: '.$tok.' Strpos: '.strpos($tok, '"').' length: '.strlen($tok).'
'; Result in the following output: Tok: "fresh Strpos: length:…
Daniel Bingham
  • 12,414
  • 18
  • 67
  • 93
3
votes
3 answers

Find first occurence of substring before a certain position

In PHP, if I have a long string, IE 10'000 chars, how would you suggest I go about finding the first occurence of a certain string before and after a given position. IE, if I have the string: BaaaaBcccccHELLOcccccBaaaaB I can use strpos to find the…
Juicy
  • 11,840
  • 35
  • 123
  • 212
3
votes
1 answer

How to search for values of giant array inside string very quickly?

I have a file of "words" that is about 5.8 MB in size and has 560,000 words in it. I'm using it to get real words from strings that are joined together. E.g. greenbananatruck could be such string. I wrote this function to be used in very fast pace.…
Martin Šajna
  • 123
  • 2
  • 8
3
votes
3 answers

My mistake with "strpos" function? php

I am trying to get strpos to search string variable $string for the phrase "test" and if it doesn't contain "test" another variable $change is redefined as $string2 (where $change has been defined previously) if (strpos($string, 'test') == false)…
David Willis
  • 1,082
  • 7
  • 15
  • 23
3
votes
1 answer

function to check array strpos and return an array

hello i would like to create a function that checks if an etry contains some words. for my login-script i would like to create a function that checks if the $_POST has some keywords in it. therfor i have thought to create an array that contains the…
bonny
  • 3,147
  • 11
  • 41
  • 61
3
votes
5 answers

PHP strpos to match querystring text pattern

I need to execute a bit of script only if the $_GET['page'] parameter has the text "mytext-" Querystring is: admin.php?page=mytext-option This is returning 0: $myPage = $_GET['page']; $match = strpos($myPage, 'mytext-'); echo $match;
RegEdit
  • 2,134
  • 10
  • 37
  • 63
2
votes
2 answers

Not returning a value in PHP in SUBSTR

Anyone know why this is not returning a value? Example $item2['data'] where it = UPC //===================================================// Author: Bob Smith Orig. Published: December 12, 1980 Format: Softcover UPC: 5960605543-04811 Price: …
Justin Lucas
  • 319
  • 2
  • 18
2
votes
2 answers

How to modify my strpos statement to target only the exact string

Warning - I'm a front end designer; Please pardon my fumbling of the PHP concepts here So I've got a PHP statement that basically outputs a class in my markup when the URL of the page matches the statement. Here it is:
Joel Glovier
  • 7,469
  • 9
  • 51
  • 86
2
votes
1 answer

PHP strpos not working

I've always had problems with strpos, I understand the num v. boolean issue, but I can NOT get this working. The $cur_key value is something like "page=>name"... $pos = strpos($cur_key, "=>"); if ($pos !== false) { $mod = explode("=>",$cur_key); …
Fluidbyte
  • 5,162
  • 9
  • 47
  • 76
2
votes
3 answers

Determine if a SQL query alters the database structure

I'm trying to find out if a string contains certain SQL commands that alter the database by: creating new tables deleting existing tables creating new table columns deleting existing table columns Right now I'm doing a strpos search for ALTER,…
Alex
  • 66,732
  • 177
  • 439
  • 641
2
votes
1 answer

PHP use str_replace, substr and strpos all together

What I am trying to do is to convert url of a video on youtube/vimeo return a new url that can be embed into an iframe and automate video embed codes. This is working like a charm. $url = "http://vimeo.com/29431603"; $orj_value = array("watch?v=",…
Mehmet Yaden
  • 277
  • 3
  • 9
2
votes
4 answers

i have faced a problem in search for arabic work inside an array

Hi everyone i have faced a problem during my working to return a response for a api the main problem is $name = "تش"; $restaurants = [ "تشك تشيكن", "بيتزا ساخنة", "كينتاكي", "تشيكن سبوت" ]; foreach ($restaurants as $restaurant) { if…
Mhammed Talhaouy
  • 1,129
  • 10
  • 14