473,799 Members | 3,866 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show only last word in a parameter

I have a parameter $name that contavins e.g. "Turn left at Blooming
Grove Turnpike/Quassaic Turnpike/RT-94 Continue to follow RT-94".
I just want to have the last word. The number of words will be different
each time.

I looked at http://be.php.net/manual/en/book.strings.php but I either
did not see it or I am looking at the wrong place (or both)

houghi
--
> Beware of he who would deny you access to information, <
for in his heart he dreams himself your master. <
Commissioner Pravin Lal: "U.N. Declaration of Rights" <
Nov 16 '08 #1
3 2791
houghi wrote:
I have a parameter $name that contavins e.g. "Turn left at Blooming
Grove Turnpike/Quassaic Turnpike/RT-94 Continue to follow RT-94".
I just want to have the last word. The number of words will be different
each time.

I looked at http://be.php.net/manual/en/book.strings.php but I either
did not see it or I am looking at the wrong place (or both)
As often happens, I found it right after posting, evin if I was looking
for it for a long time:

$name="your text with words. try to find the last word using several
spaces before the last word gsvdfg5412f_tw4 t=agast3)(@35.\ n";
preg_match("/(?<=\040)([^\s]+?)$/",trim($name),$ matches);
$name = $matches[0];

Found it on http://www.programmingtalk.com/showthread.php?t=12649

houghi
--
> Beware of he who would deny you access to information, <
for in his heart he dreams himself your master. <
Commissioner Pravin Lal: "U.N. Declaration of Rights" <
Nov 16 '08 #2
houghi wrote:
I have a parameter $name that contavins e.g. "Turn left at Blooming
Grove Turnpike/Quassaic Turnpike/RT-94 Continue to follow RT-94".
I just want to have the last word. The number of words will be different
each time.

I looked at http://be.php.net/manual/en/book.strings.php but I either
did not see it or I am looking at the wrong place (or both)

houghi
Well, you could use something like:

$name = trim($name); // Strip leading/trailing white space
$pos = strrpos($name, ' '); Find the last space
if ($pos === false) // If there is none
$word = $name; // Then only one word
else
$word = substr($name, $pos+1); // Get everything following the space
echo $word;

Assuming, of course, you always have a space as a word separator.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Nov 16 '08 #3
Jerry Stuckle wrote:
Well, you could use something like:

$name = trim($name); // Strip leading/trailing white space
$pos = strrpos($name, ' '); Find the last space
if ($pos === false) // If there is none
$word = $name; // Then only one word
else
$word = substr($name, $pos+1); // Get everything following the space
echo $word;

Assuming, of course, you always have a space as a word separator.
It is, thanks for the feedback.

houghi
--
> Beware of he who would deny you access to information, <
for in his heart he dreams himself your master. <
Commissioner Pravin Lal: "U.N. Declaration of Rights" <
Nov 16 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
10885
by: Bimo Remus | last post by:
Hi, I am currently taking a C++ class and am having problems with a homework assignment. My problem is that I need to pull the first and last words out of of a character string array which is in the form title firstName lastName. The chapter that this assignment is on deals with string arrays and includes pointers. I've seen how one can reverse the order of letters in a word using pointers so thought maybe I could discern the last word...
2
2870
by: Larry C | last post by:
Hello, I have an XML doc and I am trying to write a utility thath will allow me to change a particular word with my "title" section of theXML doc. I would like to look for a "word" in the title and then change only that "word" to something else. Below in XML file I would want to change "Issue" to "Concern". This is one snip of the XML file there may be many more instances of the word "Issue" that I would want to change. I know how...
3
3077
by: Lynn A. | last post by:
Access/Word 2000 I am trying to merge a word document with an access query that has a parameter attached to it. Could someone please suggest how to stop the parameter from appearing when the query runs. I think it might have something to do with the source document mailmerge.doc. Could it be that I'm trying to run the query from
0
1117
by: Gary Miller | last post by:
I read the MS article on Word Object and coded as implied. I instantiate a Word app: Word.Application app = new Word.Application(); Then Open a HTML document: (I’ve tried all Opens, OLD, 2000..): app.Documents.Open(ref fileName, ref missingValue, ref myTrue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue,
2
13537
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to execute a MailMerge to create mailing labels or customized letters. A label name known to MS Word MailMerge mailing label wizard may be used or a template file containing the field names Line1 thru Line5 for each record to be printed. If a...
4
8328
by: Charlie Brookhart | last post by:
I am trying to write a code for a button click event. When the button is clicked, it is supposed to bring up an open file dialog box to allow the user to select the document they which to open. That word doucment will then be opened and displayed in MS Word. The code I have below doesn't quite work the way I expected it to. First, VB is complaining that the variable readOnly is not declared. How can that be when it is declared as Dim...
1
1564
by: Bob | last post by:
I have the follwing snippet of code, lets me find a document and then open it, but thw word application does not show up. I had similara to this in vb6 and it worked, but I can't get it to show in Vs2005 Vb.Net Can anyone tell me how to show the word application from within VB.net. I need this and I need to be able to add a new file. I'll have two diffrent menu items. the edit existing file and the add new word file menu.
4
31258
by: kdubble | last post by:
Hi I am trying to get the results of a query to show only unique student records (not duplicates). Is there a simple way to make the criteria field do this? I am not too familiar with SQL. I have a student_info table, a session_info table, and a services_to_students table. What I'd like to do is query the tables to get a list of all students served between certain dates. Now, of course, between those dates,
1
2130
by: simonyong | last post by:
hello, everyone Sorry for disturb.. im newbie to asp.net im trying to do a task that as below: In a SAME datagrid, it ll show all data when user key in key word in textbox... datagrid will show out Personnel number,Firstname,Lastname...and last is direct manager personnel number i create a column in datagrid, and put symbol '+'.. if the datagrid item of each row have children, then show '+',to expand it... how parent and children...
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.