Lyleyboy Posted August 28, 2009 Share Posted August 28, 2009 Hi all, I have a prospective question. I have no code yet as this is just an idea. Does anyone know a way whereby I can access the data stored in an HTML rel tag for instance. <a href='www.google.co.uk' rel='Link to google'>Google</a> How could I extract the Link to google Thanks in advance. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted August 28, 2009 Share Posted August 28, 2009 Can you elaborate more on the context of how this will be used? Are you thinking of using cURL to get the contents of a webpage and then parsing the HTML for this? Quote Link to comment Share on other sites More sharing options...
Lyleyboy Posted August 28, 2009 Author Share Posted August 28, 2009 Firstly I should explain that I'm not too good at this. The point is to create a kind of cut down CMS. So the client uploads a page that has say a <p> tag with a rel='para1' It doesnt have to be a rel by the way, a class could work too. My code can then be like a back end. I can then pull all the details of that element i.e. the content of the <p> and put it into a form. Then save it back out. I hope that makes sense... Quote Link to comment Share on other sites More sharing options...
rhodesa Posted August 28, 2009 Share Posted August 28, 2009 you will learn soon that parsing HTML is not an easy task. if everything was perfectly coded, you could use XML libraries to do exactly what you want...but as soon as someone forgets to close a tag or has something out of order at all...the entire block of HTML is unreadable. for that reason, most people end up parsing it with commands like preg_match(). this allows you to set a matching pattern to look for. finding a single item like a <a> tag is pretty straight forward...but it gets complicated when you have nested elements Quote Link to comment Share on other sites More sharing options...
Lyleyboy Posted August 28, 2009 Author Share Posted August 28, 2009 May give it a miss then. Got to be a better way... Quote Link to comment Share on other sites More sharing options...
rhodesa Posted August 28, 2009 Share Posted August 28, 2009 without knowing what the user is uploading it's pretty hard to write. can you give an example of what would be uploaded and what you would want parsed out of it? Quote Link to comment Share on other sites More sharing options...
Lyleyboy Posted August 28, 2009 Author Share Posted August 28, 2009 The idea is that the user can upload a html document which is effectivly a letter but in HTML format. Then we can use some cool code (Which I clearly can't write yet!) to replace some details like the address and event name etc etc. So really we're creating a template so it can be re used but there won't be a finite number of documents so I don't to sit there and code each template so it can be read by php. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted August 28, 2009 Share Posted August 28, 2009 Is the HTML file they are uploading the template and you will insert data into it? Or is the person uploading an HTML file with data in it that you will extract and put into a template that is already on your server? Quote Link to comment Share on other sites More sharing options...
Lyleyboy Posted August 28, 2009 Author Share Posted August 28, 2009 They will be uploading the template. I want to then read the rel='address1' and replace it. So <p rel='address1'>PLACEHOLDER</p> and I replace the PLACEHOLDER like <p rel='address1'>1 A Street, A Town</p> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted August 28, 2009 Share Posted August 28, 2009 ok...why does rel matter here...why can't you just use something like <p rel='address1'>%ADDRESS%</p> and then find/replace on the string "%ADDRESS%"? Quote Link to comment Share on other sites More sharing options...
Lyleyboy Posted August 28, 2009 Author Share Posted August 28, 2009 No the rel was just my thought of the best way to do it. I could just go with %ADDRESS% So what I'd like to now do is to 1, Say, Which template do you want to use? 2, Open that template and replace the details. Some from the DB and some from a form like the letter's body. I can set up a template picker without too much difficulty it's just then replacing the details from both the form and based on a mysql query. Sorry if I was a bit vague at the beginning. This is just developing as we talk. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted August 28, 2009 Share Posted August 28, 2009 well...if you are using placeholders like described above, you can just use str_replace() to find/replace the values. personally, i would use Smarty though...which is a PHP Templating engine...but it might be a little bit more then you want to get into. for str_replace()...you first need to collect all your data and have that ready...then load up the template (either from a form or from something in your db)...then it's just str_replace() on the template code for each of the placeholders Quote Link to comment Share on other sites More sharing options...
Lyleyboy Posted August 28, 2009 Author Share Posted August 28, 2009 Thanks for your help. I'd guess that should fix it. Thanks again 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.