General PHP Question - Showing only first Word

  • Justin
  • Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 9 months ago #17202 by Justin
Hi, I am working on JoomDonation for my companies website, we have a what i wish program where our volunteer engineers will custom-design or modify items for people with disabilities. We are using this component to try to get support for each individual project (campaign) to support cost of this.

Anyway, what I am trying to do is take the Campaign Title:

<?php echo $item->title; ?> and alter this code to show only the first word out of the campaign title.

All Campaign's start with the child's name (Brennon's Swing, Yisroel's Voice Modulation Helper ) if I can figure out how to get Child's Name out of the title (the first word) i can then have the Donate Button say something like Help Make Brennon's Wish Come True. Right now all I can do is get it to show the entire campaign title.

If anyone could help me unlock this mystery (I don't know all that much coding) I would greatly appreciate it.

Justin

Please Log in or Create an account to join the conversation.

More
11 years 9 months ago #17239 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Re: General PHP Question - Showing only first Word
Hi

You can use explode function in PHP ( php.net/manual/en/function.explode.php ). The sample code for getting the first word could be :
Code:
$words = explode(' ', $item->title); $firstWord = $words[0] ; echo $firstWord ;

Hope this help

Tuan
The following user(s) said Thank You: Justin

Please Log in or Create an account to join the conversation.

  • Justin
  • Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 9 months ago #17249 by Justin
Hi Tuan -

Thank you so much! Works like a champ!!! Great component, too!!!

Justin

Please Log in or Create an account to join the conversation.

More
11 years 9 months ago #17257 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Re: General PHP Question - Showing only first Word
No problem Justin. I also answered your other question via support ticket. Please check the support ticket to see the detailed response .

Tuan

Please Log in or Create an account to join the conversation.

Moderators: Mr. DamDũng Nguyễn Việt