Replace markup with real code

B

bateman

Hi, what I am trying to do is the following, its causing some probs though:

I have the following in a database:
[[imagediv 100.jpg This is the description text]]
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

And want to change it to:
<div class="imagediv"><img src="/images/100.jpg" alt="100.jpg" width="200"
height="200" /><br />
This is the description text</div>
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

In the future I might want to use different codes ie [[imagediv 100.jpg This
is the description text]] to reference a different DIV.

Any ideas?
 
R

Ray Costanzo [MVP]

Can't say that I follow. What's in the database now? The entire literal
string from "[[imagediv..." to "placeholding use only."? All in one column?
What is the purpose of this data? What are you trying to acheive here?

Ray at work
 
B

bateman

Hi, sorry about that.
Yeah if I return the field from the database I get:

[[imagediv 100.jpg This is the description text]]
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

The reason for this is that I am trying to write a system for a user to
easily add a article, the bits in [[ ]] will be created by buttons they
press making it hopefully pretty much foolproof. I don't trust them with
real code!

There could be multiple instances of this in the field so what I was hoping
I could do was something like this (written in non-code code!)

Take the returned field
Go through it
if you find [[ take out the text between [[ and ]]
split into 3 parts, the first word (imagediv in this case), the picture name
(100.jpg) and the description text (This is the description text)
Then replace the [[ ...... ]] with
<div class="imagediv"><img src="/images/100.jpg" alt="100.jpg" width="200"
height="200" /><br />This is the description text</div>

Then I can use the modified string in my code, hopefully showing the picture
without ever having to explain what a DIV is!



Ray Costanzo said:
Can't say that I follow. What's in the database now? The entire literal
string from "[[imagediv..." to "placeholding use only."? All in one
column? What is the purpose of this data? What are you trying to acheive
here?

Ray at work

bateman said:
Hi, what I am trying to do is the following, its causing some probs
though:

I have the following in a database:
[[imagediv 100.jpg This is the description text]]
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

And want to change it to:
<div class="imagediv"><img src="/images/100.jpg" alt="100.jpg"
width="200" height="200" /><br />
This is the description text</div>
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

In the future I might want to use different codes ie [[imagediv 100.jpg
This is the description text]] to reference a different DIV.

Any ideas?
 
A

Aaron [SQL Server MVP]

If the end user doesn't see [[imagediv 100.jpg This is the description
text]] then why not, when they click the button, just create the whole code?

Store <img scr=100.jpg alt='This is the description text'> etc...

Why build two steps to creating HTML? It's HTML, not hyroglyphics...

--
http://www.aspfaq.com/
(Reverse address to reply.)




bateman said:
Hi, sorry about that.
Yeah if I return the field from the database I get:

[[imagediv 100.jpg This is the description text]]
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

The reason for this is that I am trying to write a system for a user to
easily add a article, the bits in [[ ]] will be created by buttons they
press making it hopefully pretty much foolproof. I don't trust them with
real code!

There could be multiple instances of this in the field so what I was hoping
I could do was something like this (written in non-code code!)

Take the returned field
Go through it
if you find [[ take out the text between [[ and ]]
split into 3 parts, the first word (imagediv in this case), the picture name
(100.jpg) and the description text (This is the description text)
Then replace the [[ ...... ]] with
<div class="imagediv"><img src="/images/100.jpg" alt="100.jpg" width="200"
height="200" /><br />This is the description text</div>

Then I can use the modified string in my code, hopefully showing the picture
without ever having to explain what a DIV is!



Ray Costanzo said:
Can't say that I follow. What's in the database now? The entire literal
string from "[[imagediv..." to "placeholding use only."? All in one
column? What is the purpose of this data? What are you trying to acheive
here?

Ray at work

bateman said:
Hi, what I am trying to do is the following, its causing some probs
though:

I have the following in a database:
[[imagediv 100.jpg This is the description text]]
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

And want to change it to:
<div class="imagediv"><img src="/images/100.jpg" alt="100.jpg"
width="200" height="200" /><br />
This is the description text</div>
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

In the future I might want to use different codes ie [[imagediv 100.jpg
This is the description text]] to reference a different DIV.

Any ideas?
 
B

Bob Lehmann

Why don't you keep the image name and description in seperate columns in the
DB?

Why does the user have to know anything about <div>? Can't you just output
that in the code?

Why are you are making it so hard on yourself with contrived data formats?


Bob Lehmann

bateman said:
Hi, sorry about that.
Yeah if I return the field from the database I get:

[[imagediv 100.jpg This is the description text]]
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

The reason for this is that I am trying to write a system for a user to
easily add a article, the bits in [[ ]] will be created by buttons they
press making it hopefully pretty much foolproof. I don't trust them with
real code!

There could be multiple instances of this in the field so what I was hoping
I could do was something like this (written in non-code code!)

Take the returned field
Go through it
if you find [[ take out the text between [[ and ]]
split into 3 parts, the first word (imagediv in this case), the picture name
(100.jpg) and the description text (This is the description text)
Then replace the [[ ...... ]] with
<div class="imagediv"><img src="/images/100.jpg" alt="100.jpg" width="200"
height="200" /><br />This is the description text</div>

Then I can use the modified string in my code, hopefully showing the picture
without ever having to explain what a DIV is!



Ray Costanzo said:
Can't say that I follow. What's in the database now? The entire literal
string from "[[imagediv..." to "placeholding use only."? All in one
column? What is the purpose of this data? What are you trying to acheive
here?

Ray at work

bateman said:
Hi, what I am trying to do is the following, its causing some probs
though:

I have the following in a database:
[[imagediv 100.jpg This is the description text]]
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

And want to change it to:
<div class="imagediv"><img src="/images/100.jpg" alt="100.jpg"
width="200" height="200" /><br />
This is the description text</div>
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

In the future I might want to use different codes ie [[imagediv 100.jpg
This is the description text]] to reference a different DIV.

Any ideas?
 
E

Evertjan.

bateman wrote on 23 nov 2004 in microsoft.public.inetserver.asp.general:
[[imagediv 100.jpg This is the description text]]
<div class="imagediv"><img src="/images/100.jpg" alt="100.jpg"
width="200" height="200" /><br />This is the description text</div>

it is simple string manipulation.

Using vbscript:

================================

s = "[[imagediv 100.jpg This is the description text]]"

s= replace(s,"[[","")
s= replace(s,"]]","")

a = split(s," ")

r = "<div class='" & a(0) & "'>"

r = r & "<img src='/images/" & a(1) & "' alt='" & a(1)

r = r & "' width='200' height='200' /><br />"

for i=2 to ubound(a)
r = r & a(i) & " "
next

result = left(r,len(r)-1) & "</div>"

================

Instring HTML quotes are replaced with single ones.

I would put the width and height in the css clas description
 
J

Jeff Cochran

Hi, what I am trying to do is the following, its causing some probs though:

I have the following in a database:
[[imagediv 100.jpg This is the description text]]
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

And want to change it to:
<div class="imagediv"><img src="/images/100.jpg" alt="100.jpg" width="200"
height="200" /><br />
This is the description text</div>
This is just some dummy text. It doesn't mean anything and is for
placeholding use only.

In the future I might want to use different codes ie [[imagediv 100.jpg This
is the description text]] to reference a different DIV.

Any ideas?

First idea is to stop trying to do this. Keep data in the database,
markup in your page language. Second is to learn to use a database.
The image file name is an attribute. The image description is an
attribute. Attributes define your columns. So you should have:

ImageNumber - An autoassigned number to use as a unique key
ImageFileName - The actual file name (possibly with path, or a
separate column for path)
ImageDescription - The descriptive text about the image.

Retrieve the image file name from your database, display that file
along with the description.

And until the user places the data in the database, you don't need a
place holder. Don't create the record.

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top