Jump to content

Removing version number of an application in a string


calande

Recommended Posts

I'm new on this forum, and I'm very happy to join you, it seems there's a lot of people around here. I love PHP/MySQL :)

 

I'm writing a small application that receives the name and version of an application as parameter, with no space in its name, ie:

 

  • Firefox2.0.0.5
  • K3B1.5
  • OpenOffice.org2.2

 

What I have to do is extract only the name from this variable, so basically I have to remove the version on the right hand side. What I did is:

 

<?php
$pbi="K3B14.5.4";
print eregi_replace('[0-9]*$', '', str_replace ('.', '', $pbi));
?>

 

Which returns "K3B" so it's working fine, but I'd like to know how you would have done it, just to see other ways of doing it. Thanks in advance!  :)

Link to comment
Share on other sites

There's no need to replace the period, it can be included in the pattern. I've also used PREG because it's the norm for me since it's more powerful.

 

<pre>
<?php
$pbi = "K3B14.5.4";
echo preg_replace('/[\d.]*\z/', '', $pbi);
?>
</pre>

Link to comment
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.