Jump to content

replacing string without removing brackets


DiavolO

Recommended Posts

First of all, I want to apologise for my incorrect english language :)

Secondly with php i'm 'not very newbie', but there is enough space to improve...

Also, I have problem with regular expresions:

I have a string which is formed like:

any word/(-s) ( any word/(-s) )

or

any word/(-s) ( any word/(-s) ) ( any word/(-s) )

 

just like:

Information (Technologies)

or

Speciality (Information Technologies) (High Grade)

 

what i need is to shorten it with only first letters of each word, like:

I (T)

or

S (IT) (HG)

 

leaving all the brackets.

Also, i have already managed with some code, which is not working correctly:

 

$test3 = str_replace(" and ", " ", $subcat5); //replacing 'and' with space
$test4 = explode(' ',$test3); 
foreach($test4 as $v){$test5.=substr($v,0,1);}
$spec_trump = strtoupper($test5); //if needed

so if string is: Speciality (Information Technologies) (High Grade)

result will be: S(T(G

what i need is: S (IT) (HG)

 

 

Can anyone help me out, with this stuff?

 

 

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.