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
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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.