creata.physics Posted June 6, 2011 Share Posted June 6, 2011 Hello guys. I've encountered a strange problem where my post parser class will not properly parse links. What I mean is, if you type, www.website.com, http://website.com, it should automatically make those links click-able. Well, it does do that, to a certain extent. If I hit enter and start a new line with the website, like this: http://site.com It will not parse the links, but if I have the url in mid sentence, it will parse it no problem. here is the link to my entire parsing script: http://pastebin.com/GaSeL4rR here is a better example of what I mean: http://zext.org/index.php?mod=roadmap&func=view&id=26 Any help at all would be greatly appreciated, I have no idea why the script is doing this, or how. Thanks in advance, Matt. Quote Link to comment https://forums.phpfreaks.com/topic/238546-my-parser-class-will-not-parse-links-properly/ Share on other sites More sharing options...
KevinM1 Posted June 6, 2011 Share Posted June 6, 2011 Which method is responsible for what you're trying to do: do_clickable or parse_message? Also, what's with all the globals? Globals and OOP should not be used together. Globals really shouldn't be used at all, regardless. Look into OO design patterns and concepts. Quote Link to comment https://forums.phpfreaks.com/topic/238546-my-parser-class-will-not-parse-links-properly/#findComment-1225831 Share on other sites More sharing options...
creata.physics Posted June 6, 2011 Author Share Posted June 6, 2011 I understand globals should not be used with OOP, thank you kindly for that, once I have a proper instance created I'll get rid of that, that is currently not my issue. it actually seems that my capture input function is what is dealing the damage here, because when i checked the text in the database, it looks like this: test<br><br>http://zext.org<br><br>www.zext.org<br><br>http://www.zext.org <br> That is how it's submitted into the database, it seems there is something wrong with my code that is parsing it, so it's something to do with $message = html_entity_decode($message); maybe? I'm not exactly sure why the link will not parse with the >http://zext.org, because it transforms it back, because if i add a space after the > manually from the database it parses the link correctly, any idea why? Quote Link to comment https://forums.phpfreaks.com/topic/238546-my-parser-class-will-not-parse-links-properly/#findComment-1225837 Share on other sites More sharing options...
KevinM1 Posted June 6, 2011 Share Posted June 6, 2011 Have you manually tested one of your stored strings with just html_entity_decode to see if it's all being decoded properly? Quote Link to comment https://forums.phpfreaks.com/topic/238546-my-parser-class-will-not-parse-links-properly/#findComment-1225844 Share on other sites More sharing options...
creata.physics Posted June 6, 2011 Author Share Posted June 6, 2011 Yes I have done this. I also didn't answer your previous question, the method responsible is parse_message, when data is inserted into the database the text is sanitised with htmlspecialchars(), and it get's decoded with html_entity_decode, what i posted above is the how the text looks once encoded, and the link to the site that shows the links unparsed is how it looks decoded. I've also tried with htmlspecialchars_decode and that doesn't seem to resolve the issue either. It's just strange, I didn't think that a simple space would be the issue, since the content is properly decoded. Any other ideas on why this may be happening? Quote Link to comment https://forums.phpfreaks.com/topic/238546-my-parser-class-will-not-parse-links-properly/#findComment-1225846 Share on other sites More sharing options...
KevinM1 Posted June 6, 2011 Share Posted June 6, 2011 Hmm... nothing is jumping out at me. You may want to double check your regex in do_clickable, since that seems to be the method that actually creates a clickable link. You can test regex here. Quote Link to comment https://forums.phpfreaks.com/topic/238546-my-parser-class-will-not-parse-links-properly/#findComment-1225850 Share on other sites More sharing options...
creata.physics Posted June 6, 2011 Author Share Posted June 6, 2011 the regex works or else the links wouldn't parse in the first place. example of the code working and not working can be found here: http://zext.org/index.php?mod=roadmap&func=view&id=26 the issue is that when i space it out, my code creates a <br> tag, the tag gets encoded with htmlspecialchars which makes it <br> so it submits the data into the db like, text<br><br>http://zext.org, since the url is not spaced after the > the link does not get parsed, when i manually add the space in from phpmyadmin the link gets created, so the regex works, just not when the url is after <br> anyway, thanks for trying to help, that is more than i can ask for. anybody else have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/238546-my-parser-class-will-not-parse-links-properly/#findComment-1225853 Share on other sites More sharing options...
KevinM1 Posted June 6, 2011 Share Posted June 6, 2011 I don't know if this will help, or if it's something you already know, but your $inside variable must not be set in those cases. Quote Link to comment https://forums.phpfreaks.com/topic/238546-my-parser-class-will-not-parse-links-properly/#findComment-1225859 Share on other sites More sharing options...
creata.physics Posted June 7, 2011 Author Share Posted June 7, 2011 What do you mean exactly? The $inside variable only gets set when tag is used, so how would it effect the rest of the script? Quote Link to comment https://forums.phpfreaks.com/topic/238546-my-parser-class-will-not-parse-links-properly/#findComment-1226216 Share on other sites More sharing options...
creata.physics Posted June 9, 2011 Author Share Posted June 9, 2011 i figured 3 days is an appropriate wait to bump this topic. i still need help with this if anybody has any ideas, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/238546-my-parser-class-will-not-parse-links-properly/#findComment-1227301 Share on other sites More sharing options...
creata.physics Posted June 12, 2011 Author Share Posted June 12, 2011 another 3 days, another bump. Quote Link to comment https://forums.phpfreaks.com/topic/238546-my-parser-class-will-not-parse-links-properly/#findComment-1228598 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.