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

Use PHP to find a string inside a string and get some values from it

I have a string like this: $string = 'this is some random text
this is some random text again
and some more randome text'; Now I would like to remove this content from it:
matt
  • 2,312
  • 5
  • 34
  • 57
-2
votes
3 answers

PHP strpos check mail on @ and

I made a little PHP script that checks if an email is valid. The only problem is that it doesn't check if the dot is BEHIND the '@'. It accept emails like this: Hi.Hello@hotmailcom when it should only accept emails like HiHello@hotmail.com This is…
Gerlof Leuhof
  • 213
  • 1
  • 7
  • 18
-3
votes
2 answers

PHP strpos() IS case sensitive for me

When I use strpos() it is case sensitive. Why? Isn't it not supposed to be? PHP v5.3.8 $file_check_result = "%PDF-1.6 %âãÏÓ"; $test = strpos($file_check_result, "pdf"); echo $test; Outputs nothing; if however I change pdf to PDF in strpos it shows…
JohnA
  • 1,875
  • 8
  • 28
  • 34
-3
votes
1 answer

PHP - If string contains '<' or '>' - strpos()

I want to do a simple kind of test to see if a string contains any HTML. In this case if the $string variable is test or it returns no for me: $string = 'test'; if(strpos($string,'<') !== 'false'){ echo 'no'; }else{ echo 'yes'; } Is…
Paddy Hallihan
  • 1,624
  • 3
  • 27
  • 76
-3
votes
1 answer

Confused with use of strpos and !==

Confused! I am trying to extract our localsites' names which are embedded in our WordPress website's structure, ie https://www.website.co.uk/site99/folderX/page. In the URL the localsite name is all lower case without any gaps, whereas the 'display…
-3
votes
1 answer

Search strpos() with a Number Range PHP

I want to search a rule, iptables, within a string that has a port blocked—and I want to show that port. For example, the rule iptables -A OUTPUT -p tcp --dport 8080 -j DROP; I'd like to be able to search by strpos the string tcp --dport 8080 -j…
-3
votes
1 answer

PHP strpos with special characters

i try to check a string with strpos(). $a = $_SERVER['REQUEST_URI']; This works just fine if (strpos($a, 'en' ) == true) But this doesn't if (strpos($a, '/en/' ) == true) - Doesn't work I tried a lot of things to escape the character or format…
Lukas Hwm
  • 3
  • 1
  • 4
-3
votes
2 answers

php find character in string but the character alone

I want to find 4 in a string. Just 4, not 44 or 14 or 4444 ... I cannot use strpos because it returns 0 when 4 is found but also when 44 is found or when 444444 is found. What function should I use? Thanks
Miguel Mas
  • 547
  • 2
  • 6
  • 23
-3
votes
2 answers

Return string if it contains specific word

I have a string. I want to write a script in PHP for return a string if it has specific characters. For example: "Hi, this is the sample.png" is a string. Now I want to output as "Hi, this is the". I.e., if the string contains .jpg, .png, then I…
Guru
  • 410
  • 1
  • 7
  • 17
-3
votes
2 answers

What is wrong with check_referrer function that i use for CSFR/XSFR protection?

i have his code in php file and i want to know how that code work. can you please explain this to me by an example (all code)? if…
Nastaran
  • 25
  • 1
  • 1
  • 6
-3
votes
1 answer

vqmod throws strpos() empty needle error

vQmod throws the following error when parsing an XML file: Warning: strpos(): Empty needle in /home/public_html/vqmod/vqmod.php on line 455 Here's the XML itself:
ᴍᴇʜᴏᴠ
  • 4,804
  • 4
  • 44
  • 57
-3
votes
1 answer

strpos is not finding needle

I have a form that posts some html to a php file i have split each line into an array and am looping through the array but anything i try and to to search,reaplace etc on ">" just returns nothing here is the php im using $catsLines = explode("\n",…
Louise McMahon
  • 1,655
  • 3
  • 15
  • 21
-3
votes
2 answers

Output everything after the first full stop in a paragraph in php

I have a header section on my site which outputs the title and the first sentence of a news article. Below I would like to output the rest of the article minus the first paragraph. Something like this would be great: // Full Article $NewsArticle =…
Alex
  • 3
  • 2
-3
votes
1 answer

PHP - strpos doesn't work

Here are examples of array $array=array(array('#0kg - 50kg','Questions?','1|2'), array('Yes','','3|4'), array('#51kg - 100kg','Questions?','5|6')); Here is function which i'm using to check if # is in string: for…
miszczu
  • 1,179
  • 4
  • 19
  • 39
-3
votes
5 answers

Evaluating booleans from strpos() in PHP

This is my code, $em= strpos($str, 'something'); $em2= strpos($str, 'something2'); $em3= strpos($str, 'something3'); ////////triggering only if either of them exist if (($em!== false)||($em2!== false)||($em3!== false)) { some action …
Abul Hasnat
  • 1,541
  • 2
  • 16
  • 23
1 2 3
48
49