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

ADVERTISEMENT

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

Jan 2, 2011

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 View Related

First Letter Of A Word In Uppercase

Sep 3, 2004

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 View Related

Keep Some Of Word Be Uppercase On Ucwords?

Jul 14, 2010

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 View Related

Make The First Character Of The Word Uppercase?

Mar 25, 2010

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 View Related

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

Jun 8, 2010

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 View Related

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

Feb 17, 2011

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 View Related

String With Uppercase

Jul 6, 2007

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 View Related

Determine If String Is All Uppercase?

Sep 30, 2007

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

View 5 Replies View Related

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

Oct 30, 2009

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 View Related

Get The Position Of An Uppercase Character In A String

May 10, 2002

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 View Related

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

Jul 21, 2010

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 View Related

Count Uppercase Words In String

Jul 25, 2009

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

View 5 Replies View Related

Regex - Detect If String Contains 1 Uppercase Letter

Dec 13, 2010

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 View Related

String Transform First Character Uppercase / Lowercase

Aug 5, 2010

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 View Related

Convert String To Uppercase But Not Html Markup?

Oct 27, 2010

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 View Related

Check If A String Has Only Lowercase / Uppercase Letters?

Jul 16, 2010

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

View 3 Replies View Related

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

Feb 12, 2011

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 View Related

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

Feb 25, 2011

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 View Related

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

Apr 16, 2011

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 View Related

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

Feb 26, 2010

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 View Related

Remove Entire Word If The Word Contains Specific String?

Oct 8, 2010

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 View Related

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

May 2, 2011

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 View Related

Attaching A String To A Normal Word Without Loosing The String

Sep 13, 2003

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 View Related

Search String For Word If Not Found Search Another Word?

Jan 24, 2011

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 View Related

Whole Word In String

May 17, 2005

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 View Related

Word In A String

Feb 4, 2007

I'm trying to check if a specific word exists in a specific string. For that I'm using strpos function, like this:

if (strpos($str, $word)==0) // do something

But this statement returns true also when $word is the first word in $str.

View 2 Replies View Related

Get Certain Word From String?

Sep 12, 2009

If i have a string like this:

$myString = "input/name/something";

How can i get the name to be echoed? Every string looks like that except that name and something could be different.

View 4 Replies View Related

Searching For A Whole Word In The String?

Nov 1, 2001

I'd like to be able to do the following.Lets say i have a string:
$found=" Justin is in the house ";

How would i go about searching for a whole word in the string?
For example: I want to find the word "in"

if i say :
eregi("in",$found), it will find me not only the word "in" but also the word "Justin" because it contains "in" .

How do i make it search for a whole word only?
Bear in mind that when i say ' a word ' i dont necessarily mean the word "in" but any word in general.

View 4 Replies View Related

Remove Word From String

Jan 5, 2007

I got this function from somewhere else:

$var = "somesomesome and in somesomei I somie, some. someone .some";
$badword = "some";
$var = preg_replace(array("/([W]+){$badword}([W]+)/","/([W]+){$badword}([W]+)/"),$1?.str_repeat("*",strlen($badword)).$2?,$var);

This is to remove word from a string but that word SHOULD not be a part of any word. for example if i want to remove "some" then "someone" should be left as it is. BUT this function is not working properly.

View 1 Replies View Related

String - How To Get First Word Of A Sentence

Mar 19, 2010

i want only the first word of a variable.. example input:

<?php $myvalue = 'Test me more'; ?>

the output should only "Test", the first word of the input.. how can i do this?

View 11 Replies View Related

Extracting The First Word Of A String?

Jun 28, 2010

I want to split a string into two variables, the first word and the rest of the string. The first word is only ever going to be one of 4 different words.

$string = explode (' ', $string, 2);
$word = $string[0];
$string = $string[1];

The above seems like it works, but I'm wondering if there is a better way.

View 3 Replies View Related

Strip First Word From A String?

Dec 1, 2010

I basically have a script that lets users post comments but I have it setup so that at the begin of every comment the user put in the script puts in hate automactically which is how I want it to work, but sometimes the user put in hating themselves and it comes out with hating hating and then users comment. how I can get it to strip out hating or hates if it is the first word in the sentence inputted by the user? At the moment I have it set to remove hating but it removes it where ever it is used in the sentence which is not good at the moment. Here is some of the code that is being used.

if (strpos($content, 'hating') !== false) {
$content = str_replace("hating", "", $content);
}

[code]....

SET story='hating " is where I have set it to put in the word hating and include it in the database when submitted.

View 2 Replies View Related

Remove Word From String ?

May 5, 2011

$arr =array("Raven Lexy","rajesh123","xw2z","lolaurita","Artin");
$arrfind= Array
(
[code]...

I have to match the above $arr with each index of $arrfind and return the remaining string will get like this.$arrfind [0]=>Ohh... Perfect![1]=>I just logged in... didn't have to make a new profile same one is stilol here whoot whoot! lol[2]=>Hey babe, so what do you think? Have you come across any bugs? We 40 pages of bugs we are fixing which should be done in a couple of weeks, than the real marketing starts

View 2 Replies View Related

Check For Word In String?

Oct 20, 2010

What is the best way to search for a word in a string

preg_match("/word/",$string)
stripos("word",$string)

View 5 Replies View Related

Get The Longest Word In A String?

Jan 4, 2011

How can I get the longest word in a string? Eg.

$string = "Where did the big Elephant go?";

To return "Elephant"

View 4 Replies View Related

Str_replace Add Word To End Of String?

Dec 10, 2009

I'm trying to add a word to the end of a sting using str_replace. After googling, I cannot find a suitable answer on how this is done. How do you define the end of a string?

I'm trying to take a string that says "Monthly-Archive" and change it to "Monthly Archive News"

My code so far:

PHP Code:

$find3 = array("-", "");$replace3 = array(" ", " News");$selectnewcat = str_replace($find3, $replace3, $CategoryName); 

View 2 Replies View Related

Regex - Get Particular Word From String?

Nov 2, 2008

Say you have a string, but you don't know what it contains. And you want to replace all occurences of a particular word or part of a word with a formatted version of the same word. For example, I have a string that contains "lorem ipsum" and i want to replace the entire word that contains "lo" with "lorem can" so that the end result would be "lorem can ipsum" but if I put the string "loreal ipsum" through the same function, the result would now be "loreal can ipsum".

View 2 Replies View Related

Replace Last Word In String?

Sep 13, 2010

$variable = 'put returns between paragraphs';

Value of this variable everytime changes.

How to add some text before the last word?

Like, if we want to add 'and', the result should be (for this example):

$variable = 'put returns between and paragraphs';

View 5 Replies View Related

Can't Detect Every Word In String

Jul 14, 2011

I have problem that it cant detect every word in string. similar to filter or tag or category or sort of..

$title = "What iS YouR NAME?";
$english = Array( 'Name', 'Vacation' );
if(in_array(strtolower($title),$english)){
$language = 'english';
} else if(in_array(strtolower($title),$france)){

[Code].....

View 3 Replies View Related

Detect Word From A String

Jul 18, 2007

I called a query from database which will display a line of string e.g id1id2id3id4.... How do i detect if the string contain the word 'id4' for example. I'm using PHP 4.3.10

View 2 Replies View Related

Extracting A Word From A String

Mar 8, 2007

I have been looking it up but cant come up with the code to extract a word from a string.

example : "Hi There I am Kieron"

I want to extract "Kieron"

It doesn't matter really if the returned value equals what i am looking for a True or False would do. But it would be handy if i could.

View 5 Replies View Related

Remove Last Word In A String?

Feb 23, 2010

How do you remove the last word in a string no matter the length and no matter what the word is?

View 3 Replies View Related

Get Word Number X From String?

Dec 13, 2009

How can I use a function to loop through a string, and "have a look at" every word in the string, probably separated by a comma, and print them out, like this:

word 1: xxxx
word 2: xxxx
word 3: xxxx

etc, and loop till it has finished?

View 1 Replies View Related

Identify A Word And Get It Into A String?

May 28, 2010

This is an example of what i'm trying to

...<?php $text = '%$%#$567hello!@#$%^& how@#$%%%$ are#$% you?'

; //ok lets say i have this <-//i want to find the word in $text without having the word and then get it into a string i have "h" and i want to find the word in $text that begins with "h" and get that word into a strin

View 8 Replies View Related

ADVERTISEMENT