Jump to content

Recommended Posts

Hello,

 

I am trying to get a string and then replace each {NO} where NO is a number

 

For example the string I am replacing

 

You have {0} steps left {1} {2} {3}

 

The function I am parsing it through

 

public static function parse($string, $array = array())
{
if(empty($array))
{
return $output;
}

for($i=0;$i<count($array);$i++)
{
$output = str_replace('{'.$i.'}', $array[$i], $string);
}

return $output;
}

 

The PHP echo

 

 echo Lang::parse($lang['quest']['steps_left'], array('3', '2', '3'));

 

What is turns out to be

 

You have {0} steps left {1} 3 {3}

 

 

Any help? Simply it needs to replace all {NUMBERS} with the array so {0} would be 3 {1} would be 2 other solutions to make the function smaller will also be appreciated

 

Thanks in advance

Edited by exze
Link to comment
https://forums.phpfreaks.com/topic/270359-var-replacement/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.