DMMのアフィリエイトID書き換え

投稿者:

PHPの正規表現とリプレイスでやればこんな感じかな?
function replace_link($str) {
 $pattern = ‘/(<a href=”)[^>]+(>[^<]+<\/a>)/’;
 preg_match_all($pattern,$str,$matches) ;
 for($i = 0 ;$i < count($matches[0]) ;$i++ ) {
  preg_match_all($pattern,$matches[0][$i],$matches_link) ;
  $link = str_replace($matches_link[1][0],””,$matches[0][$i]);
  $link = str_replace($matches_link[2][0],””,$link);
  $link_array = explode(‘/’,$link);
  $new_link = “”;
  for($h=0;$hThank you for reading this post, don't forget to subscribe!