Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
how do I use 'str_replace' in a page?
Hey
I need to replace t.jpg
with .jpg
into a page
so, can I use str_replace
for this please?
(not in an atricle, in the page itself)
Offline
#2 2009-02-17 00:36:24
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: how do I use 'str_replace' in a page?
I assume you’re talking about output from a Textpattern image tag? If so, then swap out your thumbnail tag for an image tag.
Offline
Re: how do I use 'str_replace' in a page?
Where is the “t.jpg” coming from? <txp:image_index />
? A plugin? If the latter, it would probably make more sense to modify the plugin (or create a new tag within the plugin) rather than trying to do this in the page. I suppose to do it in the page itself you could do something like:
<txp:php> echo str_replace('t.jpg', '.jpg', some_function(array('att1'=>'foo', 'att2'=>'bar))); </txp:php>
where “some_function” is the name of the tag (minus the “txp:”) and the array contains the required tag attributes. Rather awkward stuff for a page.
Code is topiary
Offline
Re: how do I use 'str_replace' in a page?
I’m using XML and JS for a flash music player (JW) custom playlist
here is an image to show the problem
now in my code I do not use any TXP tags (because I can’t it has nothing to do with TXP),
I’m using a JS tags that takes the full image url and place it where I want
(the JS tag '+plst[theIndex].image+'
)
now the image url is taken from a like-xml-txp-page (no ending of .xml but that is fine)
and in the form I am using the thumbnail tag for the small playlist images
but I still want to use the original image (big) in the “now playing” area
so I will have small images in the playlist and big images in the “now playing”
the problem is that they both using the same XML file with the same full url of the images
so that is way I need to use str_replace to replace one line of code with another
and change t.jpg to just .jpg
jsoo, your code is giving me those errors (on a live site):
Warning: Unexpected character in input:
''' (ASCII=39) state=1 in /html/textpattern/publish/taghandlers.php(2804)
: eval()'d code on line 2
-
Fatal error: Call to undefined function some_function()
in /html/textpattern/publish/taghandlers.php(2804)
: eval()'d code on line 2
where “some_function” is the name of the tag (minus the “txp:”) and the array contains the required tag attributes. Rather awkward stuff for a page.
sorry I do not understand any of this (have no knowledge in PHP/JS)
Last edited by THE BLUE DRAGON (2009-02-17 08:15:53)
Offline
Re: how do I use 'str_replace' in a page?
ohhh ok I found a way
I forgot that I do not need the player to show the images because I’m using my custom playlist
so I delete the extension of the images from the form
so in my xml file it now like this <image>/images/1</image> instead of <image>/images/1t.jpg</image>
and now I can control the extension of the images by adding the extension I need right after the JS tag
yea drinking some water can make you think right lol ;)
here is the result – click here
Last edited by THE BLUE DRAGON (2009-02-17 09:57:56)
Offline
Re: how do I use 'str_replace' in a page?
Glad you worked it out; sounds simple enough. The snippet I gave assumed you were using a Txp tag (or plugin tag).
Code is topiary
Offline
Pages: 1