2

I'm trying to create a tooltip related to world of warcraft.

Some descriptions have

|TInterface\ICONS\inv_offhand_1h_ulduarraid_d_01:24:24:1.75:1.75|t Rest of description

how can I change this string into

<img src='images/interface/icons/inv_offhand_1h_ulduarraid_d_01.png' width='24' height='24'> Rest of description

Many thanks

3
  • What have you tried? Where is your code? Why have your attempts to do this yourself failed? Commented Dec 31, 2017 at 4:03
  • I didn't know where to start, still learning php! Commented Dec 31, 2017 at 4:30
  • If you're still learning, the best way to learn is by attempt. Read the documentation and see what you can figure out on your own. Then, if you're still stuck, come to StackOverflow. Commented Dec 31, 2017 at 4:31

1 Answer 1

1

If your 100% sure the string will be in the same format you can do it like the following.

<?php
$string = '|TInterface\ICONS\inv_offhand_1h_ulduarraid_d_01:24:24:1.75:1.75|t Rest of description';

$part = explode('|', $string);
list($url, $width, $height) = explode(':', $part[1]);

$description = substr($part[2], 2);
$url = substr(strtolower(str_replace('\\', '/', $url)), 1);

echo '<img src="images/'.$url.'.png" width="'.$width.'" height="'.$height.'"> '.$description;

https://3v4l.org/H9Lum

Result:

<img src="images/interface/icons/inv_offhand_1h_ulduarraid_d_01.png" width="24" height="24"> Rest of description
Sign up to request clarification or add additional context in comments.

1 Comment

No probs, it should work fine, but may need tweaking abit if case changes e.g: inv_offhand_1h_ulduarraid_d_01 becomes inv_Offhand_1H_ulduarraid_d_01 etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.