Preg Replace / Preg Match for href in html link?

前端 未结 1 1767
执笔经年
执笔经年 2020-12-12 04:49

Anybody have a regular expression to replace the following code:

hi

with:



        
相关标签:
1条回答
  • 2020-12-12 05:41

    PHP Simple HTML Dom Parser example:

    // Create DOM from URL or file
    $html = file_get_html('http://www.google.com/');
    
    // Find all links 
    $anchors = $html->find('a');
    
    $count = count($anchors);
    
    for($i=0;$i<$count;$i++) {
        $anchors[$i]->href = 'someLink.html';
    }
    

    If you know the href of the anchor you want to replace, do something like:

    $html->find('a[href=something]', 0)->href = 'someLink.php';
    
    0 讨论(0)
提交回复
热议问题