Solved

replace text from string but keep

Posted on 2014-03-29
1
247 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
1 Comment
 
LVL 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now