Jump to content

My parser class will not parse links properly.


creata.physics

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

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.