2

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?

bilcus
  • 43
  • 2
  • 8

2 Answers2

3

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

Related question : stripos returns false when special characters is used

Php.net : http://uk3.php.net/manual/en/function.mb-strpos.php

Community
  • 1
  • 1
James Pegg
  • 181
  • 10
  • Still not working, is there a problem with a charset? Input is in windows-1250 – bilcus Jan 05 '13 at 15:54
  • this will indeed only work if the input and needle are the same charset, and if you correctly specify the charset as the 4th character. – Evert Jan 05 '13 at 16:35
  • Converted all to the same charset but still nothing. Can someone look at the source code, intented output is one line of table. Pretty lost right now but Iam sure it is something about the encoding. – bilcus Jan 05 '13 at 19:34
0

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

bilcus
  • 43
  • 2
  • 8