Last Word Of String UpperCase?


Aug 30, 2010

I try to accomplish the following.I have a string like: “volkswagen-golf-gti” **

And I want it to change the string into: “Volkswagen Golf GTI” (last part completely uppercase)

But I have some difficulties understanding preg_replace.

Right now I have the following code:
<?php
$string = 'volkswagen-golf-gti';
$string2 = ucwords(str_replace('-', ' ', $string));
$string2 = preg_replace("/s+S+$/e", "strtoupper('\1')", $string2);
echo $string2;

[Code]...

How can I change the code so it select the last part of $string2 and makes that part uppercase? So the result of echo $string2; will be: Volkswagen Golf GTI ** $string can be anything, not only volkswagen-golf-gti

View 2 Replies


ADVERTISEMENT

Ucwords(): Uppercase The First Character Of Each Word In A String Accept 'and', 'to', Etc?

How can I make upper-case the first character of each word in a string accept a couple of words which I don't want to transform them, like - and, to, etc?For instance, I want this - ucwords('art and design') to output the string below,'Art and Design'is it possible to be like - strip_tags($text, '<p><a>') which we allow and in the string?or I should use something else? please advise!

View 3 Replies

First Letter Of A Word In Uppercase

How can I make sure in php that a word always starts with an uppercase? Let's say I've got a parameter $word holding the word 'wordlowercase' and I want it to be 'Wordlowercase'.

View 1 Replies

Keep Some Of Word Be Uppercase On Ucwords?

Example in my database SMK SUNGAI PUNAI

$school = 'SMK SUNGAI PUNAI';
echo ucwords(strtolower($school));
Ouput Smk Sungai Punai

QuestionHow to make the output will be SMK Sungai Punai which the SMK still in uppercase.Update.The problem I have 10K list of school name. From PDF I converted to mysql. I copied exactly from PDF the name of schools. All in uppercase. I need a solution if can be done.

View 3 Replies

Make The First Character Of The Word Uppercase?

Do you know is there any function in PHP to make the first character of the word uppercase? Or must I write it by regular expression?

View 4 Replies

Create The Uppercase MD5 Value Of The ASCII Equivalent Of A Word?

I have a secret word (example. dirtydawg) And using PHP I want to create the uppercase MD5 value of the ASCII equivalent of the secret word. How do I do this?

View 3 Replies

Replace Words Of A String Maintain Lowercase And Uppercase Chars Of Original String?

I have, for example, this string $string='Hello World, hello world'; I have a parameter in lowercase or uppercase and I need to replace all the equal words for <stong>word</strong> If i try this:

$newstring=str_ireplace('world','<strong>world<s/trong>',$string);

The result are Hello world, hello world (lowercase w in the first word) is to be possible replace string maintain lowercase and uppercase of the original string?

View 1 Replies

String With Uppercase

I'm looking for a string function that will allow me to take a string with uppercase and lower case letters and add a space before the uppercase letters, e.g. "LeeHarveyOswald" becomes " Lee Harvey Oswald".

View 3 Replies

Determine If String Is All Uppercase?

Is there a simple way to determine if a string is all in uppercase
characters?

View 5 Replies

Check If At Least 75% Of A String Is UPPERCASE?

I'm writing bug tracking software in PHP, and today I saw this in another bug tracker:http://bugs.php.net/bug.php?id=12017Now I want to add a feature in my software which will block titles where at least 75% of all characters is uppercase.P.S. CSS will not work, because, for example if you have the word 'iPod' in your title it turns into 'ipod' which sucks

View 1 Replies

Get The Position Of An Uppercase Character In A String

Does anybody know how I can get the position of an uppercase character in a string?
For example, lets say I want to find the position of the second Uppercase character in the string: "HelloThere", which is the "T".

View 2 Replies

String - Mb_convert_case() Keep Words That Are In Uppercase?

Assuming I have a string "HET1200 text string" and I need it to change to "HET1200 Text String". Encoding would be UTF-8.

How can I do that? Currently, I use mb_convert_case($string, MB_CASE_TITLE, "UTF-8"); but that changes "HET1200" to "Het1200.

I could specify an exception, but it won't be an exhaustive. So I rather all uppercase words to remain uppercase.

View 2 Replies

Count Uppercase Words In String

is there an easy way to count uppercase words within a string?

View 5 Replies

Regex - Detect If String Contains 1 Uppercase Letter

I'm assuming I need to use regex? I'm trying to do html redirects in php in cases where the url contains at least 1 upper case letter. example: [URL] needs to be redirected to [URL] - only problem is I can't seem to find a script to detect if at least 1 capital letter exists.

View 2 Replies

String Transform First Character Uppercase / Lowercase

I have two types of strings, 'hello', 'helloThere'. What I want is to change them so they read like: 'Hello', 'Hello There' depending on the case.

View 6 Replies

Convert String To Uppercase But Not Html Markup?

Im a bit stumped on how to make a string uppercase in php while not making the markup uppercase.So for example:

<p>Chicken &amp; <a href="/cheese">cheese</a></p>
Will become
<p>CHICKEN &amp; <a href="/cheese">CHEESE</a></p>

View 4 Replies

Check If A String Has Only Lowercase / Uppercase Letters?

How do check if a string has only lowercase/uppercase letters and has at least one number in it?

View 3 Replies

Make All The Words In A String With 3 Characters Or Less Completely Uppercase?

I trying to accomplish the following:

$string = "i want to convert this string to the following";

and convert it to something like this:

echo $string;
// I Want TO Convert This String TO THE Following

Thus: Capitalize the First Letter of All Words in a string and if a word is 3 characters or less, make the whole word Capitalized in the string. How cant this be done with PHP?

View 2 Replies

Preg_match Make Sure First Character In String Is Uppercase Or Lowercase Letter?

can someone show me the regex for this preg_match. I want to make sure first letter in string is nothing but a letter, either uppercase or lowercase. I found this, but it doesnt seem to be working.

var_dump(preg_match("^/[A-Za-z]+/", $search_terms )); The line above returns false, every time.

View 2 Replies

Find A Word In A File - Make The Line That The Word Came From Into A String?

I want to find a word in a large list file. Then, if and when that word is found, take the whole line of the list file that the word was found in? so far I have not seen any PHP string functions to do this

View 4 Replies

Find Part Of A Word And Then Replace The Whole Word With A String?

so if i have the text: "this is going to be really great" and i have the needle "goi"

i want it to find going and then replace it with the link[URL]...

View 3 Replies

Remove Entire Word If The Word Contains Specific String?

I would like to do the following, preferably with PHP:

Remove an entire word if a part of the word contains a specific string. This should be case insensitive and work multiple times, e.g. on a large text.

Pseudo-code:
match = "www."
lots_of_random_text = "... hello and welcome to www.stackoverflow.com! blah blah"
result = magic_function(lots_of_random_text, "www.")

result should now equal to: "... hello and welcome to blah blah".

How would I do this the most efficient way?

View 1 Replies

Str_replace() - Remove A Word If It's Exactly The Word In String

I'm cleaning a string removing strings in this array:

$regex = array("subida", " de"," do", " da", "em", " na", " no", "blitz");

And this is the str_replace i'm using:

for($i=0;$i<8;$i++){
$twit = str_replace($regex[$i],'', $twit);
}

how do I make it only remove a word if it's exactly the word in string, I mean, I have the following phrase: "#blitz na subida do alfabarra blitz" it will return me: "# alfabarra", I don't want the first "blitz" to be removed because it has a hash "#", i want it to output: "#blitz alfabarra", is it possible?

View 2 Replies

Attaching A String To A Normal Word Without Loosing The String

In my database I have content rows that are either called <contentname>_title or <contentname>_fulltext. now when someone clicks a link on the site it goes to index.php?action=<contentname> so I guess you see where im going..

when someone goes to such a section index.php sees $action is used and attaches it to _title and _fulltext, so u get: $action_fulltext.. basicly of cuz php now sees it as one string '$action_fulltext' and not '$action'_fulltext.

View 3 Replies

Search String For Word If Not Found Search Another Word?

I would like to search a string for a word and if this word is not found I'd like it to search for another word and keep going until it find one I have seen codes to search a string but not to keep searching.

View 4 Replies

Whole Word In String

As a newbie to PHP, can someone please help me with a frustrating small problem that has defeated my searches of the PHP manual. I want to search a string of text for the occurrence of a certain word or set of words. Easy enough, but I only want to find occurences of whole words. For example, if I'm searching for "today's exam", I want to ignore "today's example".

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved