I find the DOMDocument() class handles this elegantly. This snippet of code should help you (put the entire html tag including the div
wrapper in the $tag
variable):
$d = new DOMDocument();
$d->loadHTML($tag);
$a = $d->getElementByTagName('a');
$href = $a->item(0)->getAttribute('href');
The $href
variable will have the attribute value of href.
Related Posts:
- How does printf( __( ) ); work?
- Return HTML Template Page with PHP Function
- Displaying Logged-In User Name in WordPress Menu
- Change the filename format of saved featured images
- Getting the comment number relative to all the post’s comments
- How do I add a php statement to a jQuery string
- Upload images and attachments from frontend form
- Config apple-app-site-association file with wordpress
- How to use the php if statement [closed]
- lazy load comments wordpress on click
- Use Filename for Alt and Title Tags
- Should I use wp_mail or PHP’s mail? [duplicate]
- Trying to use Ternary operators with WP Conditionals
- How can one utilize a variable as a callback function name for add_settings_field
- Filter link to existing content suggestion
- How to strip non-alphanumeric characters, convert spaces to dashes, uppercase to lowercase in this context
- Generate an array of parent/child page IDs, based on parent page name
- fallback image for featured image
- Add attribute / custom attribute to product in woocommerce
- Link to file in plugin directory from wordpress template?
- Using a switch statement in WordPress
- wp_handle_upload – The uploaded file could not be moved to wp-content/uploads/2012/09
- How to create another version of my site based on the same database
- Why is this Ajax not working?
- Pass PHP variable to JavaScript without inline JS
- Stumped on migration
- Count the number of times the search form template gets included on a page
- Where Does WordPress Make cURL Requests? How To Add cURL Option
- Using $_GET in Functions.php [closed]
- Adding nofollow to a PHP generated Nav
- How to show part of the_content?
- WordPress plugin/code to hide all things related of a user from the public
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- Call a PHP Function with Multiple Parameters that is outside the AJAX Handler
- WordPress Gravatar filter is removing my custom attributes
- How to make my custom widget appear within WordPress widgets? Plugin development
- Function works when I don’t login to WordPress but when I login then it doesn’t work
- “imagejpeg” function is not working in wordpress
- edit search.php to include subdomain posts
- Remove echo from shortcode
- PHP code to use on next & previouspage links
- Warning: Attempt to read property “ID” on null in D:\xampp\htdocs\yba\wp-content\themes\young-brand-child\functions.php on line 162 [closed]
- Illegal string offset in PHP function
- Problem with AJAX in wordpress plugin
- Displaying text if post was within 5 hours
- Trouble inputting variable into WP query
- Change “No Comments” link to “My String” on Blog Post (Find Snippet in Code or use CSS, PHP Solution) [closed]
- How to say if meta_value is greater than 0 in an array?
- Adding a tag_ID column into Categories inside the admin dashboard?
- My website is not showing Footer section
- How to get category name or ID by post?
- ACF Repeater Pagination stopped working since upgrade to php7.2
- Best Way to Change a String in a WordPress Post
- WordPress site with embedded menu – gives You don’t have permission to access /wp-content/themes/xxx/taxonomy-redirect.php on this server
- Show get_sub_field value if it exists [closed]
- How to wrap every 3 posts in a div (and close the last div too) [closed]
- Dividing the loop to style post differently
- How to Display a List of Child Pages For a Parent Page in WordPress
- How to add PHP pagination to wordpress
- include content within conditional statement?
- Custom search query on WordPress page not working
- User meta needed in query is serialized – how to unserialize safely?
- PHP calling AJAX function that relies on passed PHP function values not working
- Order by title Child Pages displayed in a Parent Page
- not outputting medium size image URL
- Help me I cannot link my font-awesome to my WordPress Theme. I have my font-awesome folder already in my project
- Can an AJAX callback function access a PHP variable which was defined during initial page load?
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Intermittent problem can the debug log give any clues?
- Echo short code syntax
- WordPress recent post
- Filter by Post Type
- Need help to create WordPress page that decodes a text file and publishes it in JSON format
- My blog posts section seems to be rendering the other blog posts inside the first? :/
- How to get total gross revenue for current month in the woocommerce dashboard status widget
- Decoding an array in PHP (from the Shopify API) [closed]
- PHP is_embed error showing up
- How fix error in the WordPress loop?
- PHP Session Variable to WordPress Error
- Run code before WordPress loads and insert data into WP if need be
- Use WP_Query Data In Cookie
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- How can I show only if custom field has content [closed]
- need help to arabic text in wordpress
- Sorting Meta Fields?
- Themes with variable width or single columns? I want to display source code
- Category List in Theme Options Page
- Showing all post from all post type in admin backstage
- Or operators in PHP [closed]
- Keeping the previous get value and add another value when submitted
- Pagination not displaying
- upload images on front by user using form
- Masking external links with internal link for member-only
- What does this if-statement do?: if($pages=’ ‘) {}
- Really slow WordPress site [closed]
- SQL query to retrieve the number of WordPress posts with all given categories
- Saving meta box data from selected option’s value in database is not working
- Create a custom plugin with dynamic child pages listing database records
- Word press – JSPDF – Sending PDF as attachment from wp_mail – Special characters
- I can’t log into my website , it says “Error: Cookies are blocked due to unexpected output”