Jump to content

Help with string stuff


rondog

Recommended Posts

I have a string:

"system_controllers_qty"

 

and i need it to be:

"system_controllers.system_controllers_qty"

 

I can use substr because the It wont always be 'system_controllers', it can be 'system_cpus' for example so I need to somehow break and the second underscore if possible. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/214382-help-with-string-stuff/
Share on other sites

Let me get this straight, are you wanting to break the string

  'system_controllers.system_controllers_qty'

so it looks like

  'system_controllers.system'

 

If this is the case, then let me know, if not, explain a little more bud.

 

Regards, Paul.

This works, but if you guys have a cleaner solution leme know, thanks!

<?php
$str = "system_controllers_qty";
$formatted = explode("_",$str);
$formatted = $formatted[0] . "_" . $formatted[1] . "." . $str;
echo $formatted; //system_controllers.system_controllers_qty
?>

Let me get this straight, are you wanting to break the string

  'system_controllers.system_controllers_qty'

so it looks like

  'system_controllers.system'

 

If this is the case, then let me know, if not, explain a little more bud.

 

Regards, Paul.

 

Looks like we posted at the same time. Refer to my post

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.