Find text between two tags/nodes

后端 未结 6 1147
北荒
北荒 2021-02-20 00:32

I thought that this would be rather straightforward, but I think the keywords are just too general so I keep getting query results for things like this and this.

Basical

6条回答
  •  北荒
    北荒 (楼主)
    2021-02-20 00:52

    For your last question "Given two tags, how can i find the text between them?"

    Well, I have this solution for you.

    var divData = $("#test").html(); // Getting html code inside div
    

    Now, using preg_match() you can obtain the text between two words, in your case the text between spans, like this:

    preg_match('/'.preg_quote($word1).'(.*?)'.preg_quote($word2).'/is', $html, $matches);
    
    $word1 = '';
    $word2 = '<';
    $html = $_POST['divData']; // Via post/get you will have to send the html code gotten in "var divData"
    

    and for each match(with a for cycle) concat em in a variable adding whitespaces between them. Then do an echo your result and in your call back function add it to your div

    This link could help you in how make a POST call in jquery jquery post

提交回复
热议问题