Solved

replace text from string but keep

Posted on 2014-03-29
1
251 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 110

Accepted Solution

by:
Ray Paseur earned 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
A responsive image gallery using flexbox 6 76
How do I add date to text file name 15 28
Change background images after 5 seconds. 12 46
Joomla Editing 3 21
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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