This topic is locked

Altering Data Output

6/9/2008 11:09:59 PM
PHPRunner General questions
P
privatelogic author

I have a field that looks like this:
08 JUL 7.5 (40)
and I want to remove the number 40 in the parenthesis and place the 7.5 in the parenthesis. My guess is that in the visual editor under the custom tab I can do something but I am clueless as to what. Any suggestions on how to go about this?

J
Jane 6/10/2008

Hi,
use str_replace(), substr() and strpos() PHP functions to find and return part of string.

Here are some examples:

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

http://php.net/manual/en/function.str-replace.php

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

P
privatelogic author 6/10/2008

Jane, I am clueless when it comes to php code which is why I bought phprunner. If possible, could you show me how with the code? This is what I've tried.
[codebox]update table set column = concat(substr(column,1,8),'(',substr(column,9,4),')')[/codebox]
And I tried this
[codebox]<?

$src = "09.2008 22.0 (102)";

$pos = strpos($src, " (");

$new = substr($src, 0, $pos-2);

$pos = strpos($new, " ");

$len = strlen($new);

$new = substr($new, 0, $pos+1)."(".substr($new, $pos+1).")";

?> [/codebox]
But neither worked.

P
privatelogic author 6/12/2008

Anyone have an idea? This works with a straight php page but I don't know how to enter this into phprunner. Help <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=30247&image=1&table=forumreplies' class='bbc_emoticon' alt=':huh:' />
[codebox]<?php
$link = mysql_connect('localhost', 'dbase', 'password');

mysql_select_db('dbase');

$sql = 'select mytable';

$r = mysql_query($sql);

echo mysql_error();

$row = mysql_fetch_row($r);

echo $row[0];

echo '<br />';

echo preg_replace('/(\d{2}\.\d{4}) (\d+\.\d+) \(\d+\)/', '$1 ($2)', $row[0]);
?>[/codebox]

J
Jane 6/17/2008

Hi,
try to use this code on the "View as" settings dialog --> Custom on the Visual Editor tab:

$value = preg_replace('/(\d{2}\.\d{4}) (\d+\.\d+) \(\d+\)/', '$1 ($2)', $value);