Jump to content

need help with str_replace


the-botman

Recommended Posts

ok guys see i need to str_replace this

<a class="scorelink" target="match_details" onclick="window.open('','match_details','width=400,height=188,menubar=no,status=no,location=no,toolbar=no,scrollbars=no,resizable=yes')" href="/default.dll/game?comp=cl_group_A&game=357186">

but this part is always different

href="/default.dll/game?comp=cl_group_A&game=357186

how do i do this i want to remove the whole string and tought str_replace would be the best

Link to comment
https://forums.phpfreaks.com/topic/183976-need-help-with-str_replace/
Share on other sites

String replacement functions are ideal when you know exactly what you want to replace.

 

If you are unsure about exactly what you want to replace but you have a vague idea of where the data you want to replace will appear, you could use pattern matching.

 

Pattern matching in PHP is done using Regular Expressions.

 

I am assuming you will always want to replace anything that appears within the quotes of the href attribute with your own text. If so, this will work:

<?php
$subject = "<a class=\"scorelink\" target=\"match_details\" onclick=\"window.open('','match_details','width=400,height=188,menubar=no,status=no,location=no,toolbar=no,scrollbars=no,resizable=yes')\" href=\"/default.dll/game?comp=cl_group_A&game=357186\">";

$replaced = preg_replace('/href=(["\'])[^\1]+\1/i', '', $subject);


echo htmlspecialchars($subject);
echo '<hr />';
echo htmlspecialchars($replaced);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.