Not logged in. · Lost password · Register
Forum: General discussion RSS
string replace
crmind #1
Member since Jan 2006 · 5 posts
Group memberships: Members
Show profile · Link to this post
Is there any way to replace some text inside a string, before it is passed to the client?

The story is that i'm using BrowseAmp to control winamp via Wap. So i'm creating my own wml skin, but the problem is that wml language doesn't really accept & (ampersand) symbol in it's code (as of W3C standarts), and it needs to be replaced with "&" or better just with "and", and as we know, many songs have this symbol in it's ID3 tags, so everytime such symbol appears, the page doesn't appear right or mainly just shows that there is an error in code and doesn't show the page at all.

The idea is to have a function something like str_replace(<#Metadata field=title>,&,and).

Can anyone help me in this one?

P.S. Thanks the author for this fantastic program!  :)
Avatar
Azimuth #2
Member since Jan 2003 · 427 posts · Location: Chicago, Illinois - USA
Group memberships: Members
Show profile · Link to this post
This JavaScript should work...

<script language="JavaScript" type="text/JavaScript">
results = ("<#Metadata field=title>").replace(/&/g, "and")
document.write(results)
</script>
crmind #3
Member since Jan 2006 · 5 posts
Group memberships: Members
Show profile · Link to this post
Thanks for the try, but that doesn't fix the problem. First of all it's because, as i know, wml 1.1 doesn't even accept javascript. Secondly, as i said before, everytime ampersand appears in the wml code, it ruins it all, even if it is inside a script, that's why i asked is there any server side solution, modifying the variable (song metadata, directory or filename - everything that could contain "&") before even passing it in to the wml. Maybe some other ideas?

I've searched for hours, trying to find the solution for this problem, and i came up with conclusion, that the only thing, that could work, is just to teach the server itself to do that, because it just doesn't support any server side language. :(
Avatar
Azimuth #4
Member since Jan 2003 · 427 posts · Location: Chicago, Illinois - USA
Group memberships: Members
Show profile · Link to this post
Ah. You did say before passed to the client.

It seems all you can do is replace the ampersand in your tags.

Maybe if there is enough interest, Henry could add an option to filter certain characters.
crmind #5
Member since Jan 2006 · 5 posts
Group memberships: Members
Show profile · Link to this post
Yeah, I once thought of that, but then that would'nt be very proffessional aproach to the solution, would it?  :)

Well, if Henry would add such an option, then I could share this skin to others, when it's finished, but if not, the next thing on my plan is to create a WML 2.0 (XHTML) skin, which could be used by newer mobile phones.
Avatar
Tom W.M. #6
Member since Feb 2003 · 40 posts · Location: La Crosse, WI, USA
Group memberships: Members
Show profile · Link to this post
If WML is XML, you should be able to wrap the song title in a CDATA block, and avoid the whole escaping issue.  E.g.:

<![CDATA[<#MetaData field=title>]]>
Of course, it's not guranteed that the cell phone browser supports CDATA blocks.

I would appreciate more extensive escaping options for BrowseAmp's output.  I would like an XML escape (&, <, >, "), and JavaScript escape (\\, \', \", \/, \b, \f, \n, \r, \t, \x##, \u####, \U########, etc., as specified at JSON.org).

UTF-8 support would be nice, too. (If it's not already there--I can't figure this out.)
This post was edited on 2006-01-10, 00:16 by Unknown user.
crmind #7
Member since Jan 2006 · 5 posts
Group memberships: Members
Show profile · Link to this post
Thank's for the idea, it works great on plain text, but doesn't work in arguments like this, because, as you know, the same CDATA tag itself doesn't dissapear anywhere:

<a href="playlist.wml?search_playlist_string=<![CDATA[<#Metadata field=artist>]]>" title="Search"><![CDATA[<#Metadata field=artist>]]></a>

Any ideas how to bypass this?

Edit: And UTF-8 support too would be very adviseable.
This post was edited on 2006-01-11, 20:40 by Unknown user.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Page created in 156.5 ms (70.7 ms) · 69 database queries in 53.4 ms
Current time: 2018-07-22, 18:45:46 (UTC +00:00)