This topic is locked
[SOLVED]

 Remove characters in a string after a certain character.

12/30/2016 4:26:19 PM
PHPRunner General questions
DealerModules authorDevClub member

Hi Everyone and Happy New Year!
Using PhpRunner 9.6
Probably a basic question but I will ask since I am not having any luck with research.
I have a csv file that is exported from someone else's application. I am importing into MySQL, no problem. One of the fields called "images" is a text string which contains multiple images separated by a semicolons and the images are by web location for example:
"https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=24387&image=1&table=forumtopics;";
What would like to do in the view page area, select this field, change to an appropriate type and show only the first image, in the above, the example would be "https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=24387&image=2&table=forumtopics"; (without quotes) .
Question:
How can I format the string to strip the characters and stop before the first ";" and format this field to show an image on view page.
I am only interested in displaying the first image and dropping the rest.
I have tried trim (each image can be a different amount of characters, so I can't use a constant number) and substr, but no luck.
Thanks for any direction.
Paul

romaldus 12/30/2016

in visual editor setup your image field as "View as Custom" and then add the following code:



$MyValue = $data['images'];

$MyCoolArray = explode(';', $MyValue);

$value = $MyCoolArray[0] ;
romaldus 12/30/2016

or if you want to display the field as real image (picture), use the following code;

$MyValue = $data['images'];

$MyCoolArray = explode(';', $MyValue);

$value = '<img src ="' .$MyCoolArray[0]. '">';
DealerModules authorDevClub member 12/30/2016

Thanks Romaldus, I have never used explode() before, worked perfectly.