Solved

PHP echo question LIMIT output

Posted on 2011-09-28
2
216 Views
Last Modified: 2012-08-13
I have a column  in a table that has data like: B*3B as well as data like MEDH*001

I do an echo like this:

<?php echo(rawurlencode($row_WADAINMATE['CELL_ASSIGNMENT'])); ?>

Open in new window


How do I alter this echo to only display the characters prior to the * ?
0
Comment
Question by:pda4me
2 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 36718183
<?php 

echo(rawurlencode(preg_replace('/^(.*)\*.*$/', '$1', $row_WADAINMATE['CELL_ASSIGNMENT']))); 

?>

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 36718816
I think the regex from Rik-Legger looks correct.  I would probably do it something like this:

$arr = explode('*', $row_WADAINMATE['CELL_ASSIGNMENT']);
echo rawurlencode($arr[0]);

http://php.net/manual/en/function.explode.php

There is also some combination of strpos() and substr() that would work, too.  Lots of ways to skin this cat!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question