• Resolved Begin

    (@bentalgad)


    I don’t really understnd how to work with this preg_match,
    but I think it can do what I need easily…

    I need him to echo back only the text that is inside for example
    two <b> signs or <sdfg> signs or what ever sign I will give him…

    Does anyone know’s how to do that?

Viewing 3 replies - 1 through 3 (of 3 total)
  • $test = '<html><head></head><body><p>hi</p><p><b >hello</b><b>Goodbye</b></p></body></html>';
    preg_match_all("#<b\b[^>]*>(.*?)</b\b[^>]*>#",$test,$matches);
    print_r($matches);

    This is very basic and not very robust. A tag like < b> will throw it off though <b > won’t. Basically the syntax comes from here.

    Thread Starter Begin

    (@bentalgad)

    Great! thank’s.

    But i can’t get it completly working as I want:

    I wrote:

    $preprice = "text text text <price>34</price> more text text text";
    preg_match_all("#<price\b[^>]*>(.*?)</price>#", $preprice, $matches);
    $price = "$matches";
    
    add_post_meta($post_ID, 'price', $price);

    and it add a post meta with a value “array” and not “34”
    as I want…

    ?

    Thread Starter Begin

    (@bentalgad)

    I got it right, thank’s!!! it’s just great!!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get only text between a <b> sign with “preg_match” ?!’ is closed to new replies.