1

I need to replace this html code:

Actors: Mamoru Miyano, Kappei Yamaguchi, Aya Hirano

with this code:

Actors: <a href="http://example.com/actor/Mamoru Miyano">Mamoru Miyano</a>, <a href="http://example.com/actor/Kappei Yamaguchi">Kappei Yamaguchi</a>, <a href="http://example.com/actor/Aya Hirano">Aya Hirano</a>

Is it possible?

In control panel i cannot see actors list i see only this: [xfvalue_actors]

and i tried to replace as this:

<a href="http://myfilms.ga/actor/<?php $str = '[xfvalue_actors]'; echo preg_replace('/, /', '"></a><a href="http://myfilms.ga/actor/', $str, 20); ?>/">[xfvalue_actors]</a><br />

but i get it:

<a href="http://myfilms.ga/actor/Mamoru Miyano"></a><a href="http://myfilms.ga/actor/Kappei Yamaguchi"></a><a href="http://myfilms.ga/actor/Aya Hirano">Mamoru Miyano, Kappei Yamaguchi, Aya Hirano</a><br />
Gordon
  • 312,688
  • 75
  • 539
  • 559
Nevermind23
  • 375
  • 1
  • 4
  • 14

3 Answers3

2

Can you try this and tell me how it is working?

<?php 
$str = '[xfvalue_actors]'; 
$arrActors = explode(',', $str);
$out = '';
foreach ($arrActors as $actor) {
    $out .= "<a href='http://myfilms.ga/actor/{$actor}'>{$actor}</a><br />,";
}
echo "Actors: " . substr($out, 0, -1);
?>

As a result I am getting:

Actors: <a href='http://myfilms.ga/actor/Mamoru Miyano'>Mamoru Miyano</a><br />,<a href='http://myfilms.ga/actor/ Kappei Yamaguchi'> Kappei Yamaguchi</a><br />,<a href='http://myfilms.ga/actor/ Aya Hirano'> Aya Hirano</a><br />

Hope this is what you need! :)

Antoan Milkov
  • 2,152
  • 17
  • 30
0

You can use str_replace if you want to replace a part of string

$old = "Actors: Mamoru Miyano, Kappei Yamaguchi, Aya Hirano";
$new = "Actors: <a href="http://example.com/actor/Mamoru Miyano>Mamoru Miyano</a>, <a href="http://example.com/actor/Kappei Yamaguchi>Kappei Yamaguchi</a>, <a href="http://example.com/actor/Aya Hirano>Aya Hirano</a>";


str_replace($old,$new,$your_string)

But in your case you are referring to HTML . so may be you can use jquery

var replaced = $("body").html().replace('Actors: Mamoru Miyano, Kappei Yamaguchi, Aya Hirano','The new string');
$("body").html(replaced);
Kanishka Panamaldeniya
  • 17,302
  • 31
  • 123
  • 193
  • In Admin Panel This: Mamoru Miyano, Kappei Yamaguchi, Aya Hirano Looks as: {actors} so i cannot replace it so easy – Nevermind23 Oct 18 '14 at 09:44
0

if you are trying to change based on a certain condition..try if loop(php)

<?php if(condition){ ?> Actors: <a href="http://example.com/actor/Mamoru Miyano>Mamoru Miyano</a>, <a href="http://example.com/actor/Kappei Yamaguchi>Kappei Yamaguchi</a>, <a href="http://example.com/actor/Aya Hirano>Aya Hirano</a><?php }else { ?>Actors: Mamoru Miyano, Kappei Yamaguchi, Aya Hirano <?php } ?>
subas chandran
  • 13
  • 1
  • 1
  • 5