Welcome Guest, Not a member yet? Register   Sign In
Parse custom html tags into CI functions with variables.
#1

[eluser]duffy0[/eluser]
I don't know how to do this, but I am trying to parse my custom html tags into something I can use in CodeIgniter.

I want to change this:
<il:profile-pic username="duffy0" width="200" height="150" linked="false" />

into this in my view:
&lt;?=$this->profile_model->profilepic('duffy0', '200', '150', 'false')?&gt;

Any ideas?
#2

[eluser]duffy0[/eluser]
I have other custom html tags i want to parse:

<il:button href="welcome/index" title="Home" />
<il:boxtitle href="followers/index" title="Followers" />

These are similar to Facebook's Markup Language, but I have no idea how to parse them. They all turn into php functions. Is there a template library I could use?
#3

[eluser]pistolPete[/eluser]
[quote author="duffy0" date="1234745851"]
<il:profile-pic username="duffy0" width="200" height="150" linked="false" />
[/quote]

Have a look at regular expressions:
Code:
// this is the string you are parsing
$subject = '<il:profile-pic username=\"duffy0\" width=\"200\" height=\"150\" linked=\"false\">';

// this is the regular expression
$pattern = '@\<il\:profile-pic username\=\"(.+)\" width\="([0-9]+)\" height\=\"([0-9]+)\" linked\=\"(true|false)\"\>@isU';
$result = preg_match($pattern, $subject, $subpattern);

// now the values for username, width, height and linked are in $subpattern
echo '<pre>'.print_r($subpattern, TRUE).'</pre>';

This will produce the following output:

Code:
Array
(
    [0] => <il:profile-pic username="duffy0" width="200" height="150" linked="false">
    [1] => duffy0
    [2] => 200
    [3] => 150
    [4] => false
)
#4

[eluser]duffy0[/eluser]
Is there any way this can be implemented in a view file without slowing down the server so much?
#5

[eluser]pistolPete[/eluser]
Well this depends on how many of these tags are there, bu I recommend caching the result of the parsing everytime the contents of the page have changed.
#6

[eluser]duffy0[/eluser]
Well... I would love to cache the result, but users hate caching when it's a social network.. Is there some way to use the parser?
#7

[eluser]TheFuzzy0ne[/eluser]
Check out the [url="http://developers.facebook.com/fbopen/"]Facebook Open Platform[/url]. You should be able to learn a lot from the code for their FBML parser. Please check the licensing first, though. I'm sure it's probably copyrighted, but I'm quite sure there are no laws against learning from it.
#8

[eluser]duffy0[/eluser]
I didn't even know this even existed! Thanks a bunch I will take a look and see if I can learn anything from it and let you know.
#9

[eluser]TheFuzzy0ne[/eluser]
Me neither until today!

All hail the mighty Google!

Good luck! Smile
#10

[eluser]pistolPete[/eluser]
Another option would be OpenFBML:

Quote:OpenFBML is an open-source FBML parser programmed in PHP. It allows you to use FBML tags without outside of the facebook platform, facebook connect or open platforme.

http://code.google.com/p/open-fbml/

[quote author="duffy0" date="1234749524"]Well... I would love to cache the result, but users hate caching when it's a social network.[/quote]

Why should they hate caching? If you do serverside, partial chaching which gets refreshed everytime a change has been made...




Theme © iAndrew 2016 - Forum software by © MyBB