Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

replace text from string but keep

Posted on 2014-03-29
1
Medium Priority
?
257 Views
Last Modified: 2014-04-13
Im trying to create a simple 'cookbook' of code and want to create snippets of code (like experts-exchange):-
My Code

Open in new window


What my plan is to do line experts exchange and do someting like:-

[codeSnippet]My Code[/codeSnippet]

I know how to find the start, and the end, but would like to pull out the code inbetween and replace with my own details, for example:-


This is some text above
[codeSnippet language=css]My Code 1[/codeSnippet]
Between text
[codeSnippet language=html]My Code 2[/codeSnippet]
And some text at the bottom

Should look like:-

This is some text above
<div class="codeSnippet">My Code 1</div>
Between text
<div class="codeSnippet">My Code 2</div>
And some text at the bottom

Any ideas how I can pull the tag out, delete the tag and then insert it into my own code?

On an improvement I wanted to include the language tag out of the first tag so I can colour the code for a bit of ease of reading.
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39963953
If you follow the BBCode rules, you may find the PHP Bulletin Board Code Extension is helpful.

For display, HTML has the <code> and <pre> tags that are usually used in web page display of computer code.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question