|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
how to replace???
ok im making a forum and i dont know where to start with the bb forum code.
how would that be done?? for example: when someone clicks on a smily it inserts :smily: into the text, how would i convert that into <img src="images/emoticons/smily"> when the post is displayed?? also, for example, when they want to make text bold: (excuse the spaces) [ b]this text bold[ /b] it ends up like: this text bold and for example when they want to post images: [ img]imgurl.jpg[ /img] any ideas on how that would be done?? i tried using the Replace() function but i didnt seem to get it right??? |
|
#2
|
|||
|
|||
|
You can do this with replace() and replaceNoCase(), or look into using regular expressions with reReplace() and reReplaceNoCase(). If you search around on the web you will find tons of regular expression tutorials and examples.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
||||
|
||||
|
ok i got the replace() function to work, but my question to you now is, how do i get it to work if i have to replace multiple things in a post??
|
|
#4
|
|||
|
|||
|
Use the 'All' argument to the replace() function, which I sure you already know from reading the documentation.
http://livedocs.macromedia.com/cold...8.htm#wp1111342 ![]() Again I'll mention what has already been said before, I'm here to help, but for basic questions like this about a function, PLEASE read the docs first! Last edited by kiteless : September 13th, 2004 at 01:27 PM. |
|
#5
|
||||
|
||||
|
no no you dont understand, here is an example of my code
#ParagraphFormat(Replace(topiccontent, ":bigsmile:", "<img src=images/emoticons/biggrin.gif>", "all"))# now you see there how i have only one smily to be replaced, well i got about 15 more different smilys that i want to replace, how would i do that? |
|
#6
|
|||
|
|||
|
One option would be to create a structure that maps the smiley name to the image. Then loop over the structure and run a replace for each key in the struct. Something like this (pseudocode):
smileyStruct = structNew() smileyStruct.bigSmile = ''biggrin.gif" cfloop collection="#smileyStruct#" item="thisSmiley" set myText = replace( myText, ':#thisSmiley#:', '<img src="images/emoticons/#smileyStruct[thisSmiley]#">', 'All' ) /cfloop You could also define the mappings in an XML file, read them in, and loop over them that way. Just another approach. Hope that helps. |
|
#7
|
||||
|
||||
|
ok i made this code, but it still shows the smilies as they were entered into the database :smiley:
my code is below <cfset smileyStruct=structNew()> <cfset smileyStruct.angry= "angry.gif"> <cfset smileyStruct.bigsmile= "biggrin.gif"> <cfset smileyStruct.confused= "blink.gif"> <cfset smileyStruct.blush= "blush.gif"> <cfset smileyStruct.whew= "closedeyes.gif"> <cfset smileyStruct.cool= "cool.gif"> <cfset smileyStruct.grin= "dry.gif"> <cfset smileyStruct.exclamation= "excl.gif"> <cfset smileyStruct.happy= "happy.gif"> <cfset smileyStruct.huh= "huh.gif"> <cfset smileyStruct.laugh= "laugh.gif"> <cfset smileyStruct.mad= "mad.gif"> <cfset smileyStruct.ohmy= "ohmy.gif"> <cfset smileyStruct.rolleyes= "rolleyes.gif"> <cfset smileyStruct.sad= "sad.gif"> <cfset smileyStruct.smile= "smile.gif"> <cfset smileyStruct.tongue= "tongue.gif"> <cfset smileyStruct.unsure= "unsure.gif"> <cfset smileyStruct.wink= "wink.gif"> <cfloop collection="#smileyStruct#" item="thisSmiley"> <cfset topiccontent = replace( topiccontent, ":#thisSmiley#:", "<img src=images/emoticons/#smileyStruct[thisSmiley]#>", "All" )> </cfloop> #ParagraphFormat(topiccontent)# |
|
#8
|
|||
|
|||
|
I would probably use replaceNoCase() instead of replace() to handle any case situation.
The key is to confirm that this line of code is working: <cfset topiccontent = replace( topiccontent, ":#thisSmiley#:", "<img src=images/emoticons/#smileyStruct[thisSmiley]#>", "All" )> If you replace the varaibles with the values you defined, does it work? Like this: <cfset topiccontent = replace( topiccontent, ":angry:", "<img src=images/emoticons/angry.gif>", "All" )> |
|
#9
|
|||
|
|||
|
Ah, in fact I can almost guarantee that it is a case problem, as CF treats structure keys as capitals. Try it like this:
<cfloop collection="#smileyStruct#" item="thisSmiley"> <cfset topiccontent = replaceNoCase( topiccontent, ":#thisSmiley#:", "<img src=images/emoticons/#smileyStruct[thisSmiley]#>", "All" )> </cfloop> |
|
#10
|
||||
|
||||
|
nope still same
![]() |
|
#11
|
|||
|
|||
|
Well I'm not sure what you are doing wrong because this works for me:
<cfset smileyStruct=structNew()> <cfset smileyStruct.angry= "angry.gif"> <cfset smileyStruct.bigsmile= "biggrin.gif"> <cfset smileyStruct.confused= "blink.gif"> <cfset smileyStruct.blush= "blush.gif"> <cfset smileyStruct.whew= "closedeyes.gif"> <cfset smileyStruct.cool= "cool.gif"> <cfset smileyStruct.grin= "dry.gif"> <cfset smileyStruct.exclamation= "excl.gif"> <cfset smileyStruct.happy= "happy.gif"> <cfset smileyStruct.huh= "huh.gif"> <cfset smileyStruct.laugh= "laugh.gif"> <cfset smileyStruct.mad= "mad.gif"> <cfset smileyStruct.ohmy= "ohmy.gif"> <cfset smileyStruct.rolleyes= "rolleyes.gif"> <cfset smileyStruct.sad= "sad.gif"> <cfset smileyStruct.smile= "smile.gif"> <cfset smileyStruct.tongue= "tongue.gif"> <cfset smileyStruct.unsure= "unsure.gif"> <cfset smileyStruct.wink= "wink.gif"> <cfset topicContent="This is the content. Here is a big smile: :bigsmile: And here is some more text." /> <cfloop collection="#smileyStruct#" item="thisSmiley"> <cfset topiccontent = replaceNoCase( topiccontent, ":#thisSmiley#:", "<img src=images/emoticons/#smileyStruct[thisSmiley]#>", "All" )> </cfloop> <cfoutput> #ParagraphFormat(topiccontent)# </cfoutput> |
|
#12
|
||||
|
||||
|
i will email you a copy of my code so you can analize it, cause that works for me too but i dont know what could be causing it not to work in the page...
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > how to replace??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|