0

So

I have code :

$wzor = '/^<span class=\"person\">(.*?)</span>/';
$text = str_replace($wzor, '', $text);

I want to remove all spans with class person from my text but my code doesn't work

my input is like:

<ul>
    <li><span class="label">Spółdzielnia Socjalna Giełda Pracy</span><span class="person">0zł brutto</span></li>
</ul>
<ul>
    <li><span class="label">LOYD SPÓŁKA AKCYJNA</span><span class="person">0zł brutto</span></li>
</ul>
<ul>
    <li><span class="label">Loyd 8 Sp. z o.o.</span><span class="person">0zł brutto</span></li>
    <li><span class="label">Loyd 1 Sp. z o.o.</span><span class="person">0zł brutto</span></li>
    <li><span class="label">Loyd 7 Sp. z o.o.</span><span class="person">0zł brutto</span></li>
</ul>
<ul>
    <li><span class="label">Spółdzielnia Socjalna Giełda Pracy</span><span class="person">0zł brutto</span></li>
</ul>
<ul>
    <li><span class="label">Spółdzielnia Socjalna Icelandia</span><span class="person">0zł brutto</span></li>
</ul>
<ul>
    <li><span class="label">Spółdzielnia Socjalna Giełda Pracy</span><span class="person">0zł brutto</span></li>
</ul>bonusbonus
<ul>
    <li><span class="label">Spółdzielnia Socjalna Giełda Pracy</span><span class="person">0zł brutto</span></li>
</ul>bonus
1
  • 2
    Related?! Commented Nov 27, 2014 at 13:43

2 Answers 2

1

The ^ at the start forces the match to be at the beginning of the string. Also, there is an unescaped / in </span>

This should work :

$wzor = '/<span class=\"person\">(.*?)<\/span>/';

Also use preg_replace instead of str_replace. ;)

Sign up to request clarification or add additional context in comments.

1 Comment

You can use a different character as delimiter if you need to use '/' in your regexp. And there is no need to escape the quotes. $wzor = '#<span class="person">(.*?)</span>#' is easier to read.
0

If you want to use Regular Expressions, you need to use the preg_replace() function. Also there was an error in your regex, that did not escape the slash character. This one works:

<span class=\"person(.*?)<\/span>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.