I am in the hard task of rewriting a template system, specificly to support repeating content of a forum script.

I am currently tyring this with a dummy file at the moment and I am stuck on one part.
What is basically does, is load the following html which has worked well, but what I need to do is a value where it cuts the html between 2 tags so I can use it to be repeated before reinserting.

$string = '<div class="boxone">Memberlist</div>

<!-- row -->
Username is {USERNAME}
<!-- row -->';

So in short, what I am looking to do is cut 'Username is {USERNAME}' out of the string, preferbly in a function, so I would end up with something similar to bellow

$snippet = bock('row',$string);
print $snippet; // outputs Username is {USERNAME}

Any help would be appreciated

Recommended Answers

All 6 Replies

str_replace should do what you are trying to do. Give it a quick look.

I looked at that first, but thats only replacing, what I need is the opposite.
Instead of replacing, I want it to find whats between the html comments and return it to me.

Anyone. I basically want to make it so I have 1 template file per page, and make a function to repeat a certain bit for rows or posts ect.

So I need a function where it can look at a string, find the html between the html comments then return it as a usable var

Anyone, theres got to be a way to do this, it was done in phpbb2. Its not rocket science but looking through php.net I cant find the right function.

Anyone. I basically want to make it so I have 1 template file per page, and make a function to repeat a certain bit for rows or posts ect.

So I need a function where it can look at a string, find the html between the html comments then return it as a usable var

You could search for a pattern, for example search for the opening tag then put the position of that into a variable, then find the closing tag and take the position of that. Then withdraw the position of the closing tag from the position of the opening tag.
This way you have the start position and the length of what is between and can use the substr function to fetch what is in there.

How would I go about doing that

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.