langauld Posted March 22, 2009 Share Posted March 22, 2009 Hi gurus, I've ran into a bit of a problem, and I can't seem to find the right search terminology to find myself a solution.. I'm not an experienced programmer in PHP by any means, I only know the basics, and how it works etc. At the moment, I'm creating a website that displays products for sale. It uses WordPress as it's CMS, although I've added and removed bits of code all over the place to make the site work just the way I want it to. The problem I'm having is regarding a plugin called 'CFI (Custom Field Image)', which basically allows the user to add a picture to their post as a custom field, rather than embedding it into the post data. If you go to http://claremasonjewellery.co.uk/DATABASE you can see it working on the category pages. In the 'loop', I call 'custom_field_image' which generates the dynamic <img> for each post. What I want to do is make it so that when viewing a single post, clicking on the large image makes it full size in a separate window. However, I cannot for the life of me get JUST the 'src' part of the img info that the function creates, because the place where it's generated is embedded inside two more nested functions. Incase you're a little lost and I'm not explaining myself well enough, I made the error of writing <?php $imageData = explode(" ", custom_field_image); print $imageData[3]; ?> to try and make happen what I want, but it instead just printed another image. Someone please help Quote Link to comment Share on other sites More sharing options...
langauld Posted March 29, 2009 Author Share Posted March 29, 2009 Sorry to bump, I use forums myself and I know it isn't 'the thing to do'.. But I quite urgently need a solution to this, so if anyone knows one who missed it when I first posted, would you mind lending me a hand? Quote Link to comment Share on other sites More sharing options...
killah Posted March 29, 2009 Share Posted March 29, 2009 You could try preg_match_all or maybe preg_replace to strip everything out except for src="XX" then another preg_replace to strip out src="" leaving XX, altho it can just be done with one preg_replace. I can post the code for you. How ever, you need to tell me. Is the url inside ' or "? Example with ': <img src='link'> Example with ": <img src="link"> Quote Link to comment Share on other sites More sharing options...
langauld Posted March 29, 2009 Author Share Posted March 29, 2009 Excellent! Thank you so much, I didn't think the preg_match_all() or preg_replace() functions would work with another function as their data source.. Just like the explode() didn't work. But if you think it will, and it does, then I'm uber grateful!! The img src url is inside "s, not 's P.s. If you could write out the code for me, that'd be much appreciated.. I've never used those functions before so have no idea how they work! Quote Link to comment Share on other sites More sharing options...
killah Posted March 30, 2009 Share Posted March 30, 2009 <?php $string = 'some text with image <img src="url_here">'; $new = preg_replace('~(.*)<img src="(.*)">~i','$2',$string); echo $new; ?> Returns: url_here Hope that help's. If it don't just reply back and ill try another small solution. Quote Link to comment Share on other sites More sharing options...
langauld Posted March 31, 2009 Author Share Posted March 31, 2009 Thanks for your help. That hasn't worked though, it printed out the whole of the function, not just the image part. Maybe it'd be helpful if I told you what the function prints? Writing simply: <?php custom_field_image();?> ..returns the following: <img src="http://localhost/wp-content/uploads/2009/02/p1030447-370x277.jpg" class="cfi alignleft" alt="Indian Summer Intertwined Bracelet" title="Indian Summer Intertwined Bracelet" /> Using the code you gave me doesn't have any effect of what it prints, it just writes out exactly the same result! I don't think you fully understood my problem though, so it's not your fault! Does anyone else know what I could do? Quote Link to comment Share on other sites More sharing options...
langauld Posted April 3, 2009 Author Share Posted April 3, 2009 Hmm, I'll assume it just isn't possible then Quote Link to comment Share on other sites More sharing options...
killah Posted April 4, 2009 Share Posted April 4, 2009 It's possible yes. It's just take this for example. $string = 'some url <img src="url_here">'; and with teh code above, it returns url_here unfortunatly put this there: $string = 'some url <img src="url_here" title="attribute" alt="attribute" width="110" height="110">'; it will return: url_here" title="attribute" alt="attribute" width="110" height="110 so in other word's it's take all the code inside the src=" till "> i tried removing the end > and no hope. Ill continue trying tho. Quote Link to comment Share on other sites More sharing options...
yami007 Posted April 7, 2009 Share Posted April 7, 2009 no way, it should work!! then maybe u should print all the code here Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.