WordPress.org

Ready to get started?Download WordPress

Forums

Truncate "the_content" to an element. (4 posts)

  1. jlan2747
    Member
    Posted 1 year ago #

    Example:
    Heres the_content so far:

    <object width="560" height="315">
    				<param name="movie" value="http://www.youtube.com/v/JaQtWg6bifw?fs=1"></param>
    				<param name="allowFullScreen" value="true"></param>
    				<embed src="http://www.youtube.com/v/JaQtWg6bifw?fs=1&rel=0" type="application/x-shockwave-flash" width="560" height="315" allowfullscreen="true"></embed>
    				</object>
    <img alt="The Atheist Experience Episode #766: Viewer Calls" src="http://www.axpweekly.com/wp-content/uploads/2012/06/20180_the_atheist_experience_default.jpg" />
    Episode #766: Viewer Calls WEBSITE: www.axpweekly.com

    I want to truncate to just the object:

    <object width="560" height="315">
    				<param name="movie" value="http://www.youtube.com/v/JaQtWg6bifw?fs=1"></param>
    				<param name="allowFullScreen" value="true"></param>
    				<embed src="http://www.youtube.com/v/JaQtWg6bifw?fs=1&rel=0" type="application/x-shockwave-flash" width="560" height="315" allowfullscreen="true"></embed>
    				</object>
  2. tgxn
    Member
    Posted 1 year ago #

    Use regex to detect the tags, then use that.

    $source = <Full Content>;
    preg_match("'.*?(<object .*?>.*?</object>).*?'si", $source, $match);
    if($match) echo $match[1];
  3. jlan2747
    Member
    Posted 1 year ago #

    Worked like a charm! Thankyou :)

    For those who just got here, replace
    <Full Content>;
    with
    get_the_content();

  4. tgxn
    Member
    Posted 1 year ago #

    Good to hear.

    Can you mark this as resolved? Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic