WordPress.org

Support

Support » Plugins and Hacks » [Resolved] get only text between a <b> sign with “preg_match” ?!

[Resolved] get only text between a <b> sign with “preg_match” ?!

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

    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…

    ?

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

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