bilcus
bilcus

Reputation: 43

Strpos failed to find special characters

I am using this piece of code to find if substring is present in a string but when it runs into a special character it fails even when the character is clearly present.

//Code out of context
if (strpos($pieces[$i], 'Č<br>t') !== false) {
    $out .= $pieces[$i];}

---fails, Č not found

if (strpos($pieces[$i], 'S<br>t') !== false) {
    $out .= $pieces[$i];}

---OK

Input

<td >Č<br>t</td>
<td >S<br>t</td>

Via

$str = file_get_contents($url);

(Entire code)

What am I doing wrong?

EDIT: Still not working. Input page is in windows-1250, is the problem in it?

Upvotes: 2

Views: 3157

Answers (2)

bilcus
bilcus

Reputation: 43

If mb_strpos does not work, try to check your NetBeans encoding or create new project, worked for me.

Upvotes: 0

James Pegg
James Pegg

Reputation: 191

Try using mb_strpos instead, it's meant to handle special characters.

Related question : stripos returns false when special characters is used

Php.net : https://www.php.net/manual/en/function.mb-strpos.php

Upvotes: 2

Related Questions