Jump to content

query to return value after a certain character in a field


glennn.php

Recommended Posts

ok, this is clearly 1st grade code for some, but i'm not there yet - I'm querying posts in WordPress, and the post_content will always have an image in the beginning of the post followed by the content. i don't want to get the image, just the content that's after the image, which is wrapped in anchor tags, of course.

 

<a href="http://path/to/image.jpg"><img src="http://path/to/image.jpg" /></a> <p>Post content yadda, yadda, hoowie</p>

 

obviously a character count won't work, so i need to get anything that follows the first "</a>", say...? is this the best way, or is there an easier way?

 

thanks for anyone's help.

 

GN

 

 

 

Link to comment
Share on other sites

no, cause even these image names are going to be different.

 

i'm ok keeping the tags, i just want to use the </a> as a delimiter and store everything up to and including that in one var and everything after that in another var. sorry i wasn't as clear the first time.

 

 

im realizing that this is probably a php question, perhaps using substr()..? my apologies for this being in mysql...

Link to comment
Share on other sites

Well, it can be done in a MySQL query if you'd like (as long as you're sure the delimiter will always be '</a>').

 

SELECT 
CONCAT( SUBSTRING_INDEX( `field` , '</a>', 1 ) , '</a>' ) AS first_half, 
SUBSTRING_INDEX( `field` , '</a>', -1 ) AS second_half
FROM table
WHERE whatever_field = some_value

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.