Skip to main content
November 30, 2007
Answered

convert asp code to php

  • November 30, 2007
  • 11 replies
  • 983 views
i am new to php, transferring from asp and would like help in converting some code i have used with asp?

it is a function code to hilight results from a database search.
this is the code in asp

<%

Function HilightResults(sDataValue, sSearchString)
HilightResults = Replace(UCase(sDataValue), UCase(sSearchString), "<span style='color:red;'>" & UCase(sSearchString) & "</span>")
End Function

%>

<td class="WADAResultsTableCell"><%=HilightResults((WADALABEL1.Fields.Item("Item_number").Value), Request("S_Item_number"))%></td>

thanks for your help
Jim Balthrop
JBWebWorks.com
This topic has been closed for replies.
Correct answer Newsgroup_User
jim balthrop wrote:
> when you search with any of the other search text fields, the return for
> column 'mfg_name' is '-1'

I'm working completely in the dark here, because I don't know what
variables you're using to retrieve the data from the database, or what
the raw data looks like. However, I think the following might do what
you want:

<?php
function highlightResults($dataValue, $searchString) {
return preg_replace("/$searchString/i", '<span
style="color:red;">'.strtoupper($searchString).'</span>', $dataValue);
}
?>

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

11 replies

Inspiring
November 30, 2007
jim balthrop wrote:
> Function HilightResults(sDataValue, sSearchString)
> HilightResults = Replace(UCase(sDataValue), UCase(sSearchString), "<span
> style='color:red;'>" & UCase(sSearchString) & "</span>")
> End Function

function highlightResults($dataValue, $searchString) {
str_replace(strtoupper($dataValue), strtoupper($searchString), '<span
style="color:red;">'.strtoupper($searchString).'</span>');
}

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
December 1, 2007
thanks David

what about the search field part of the code in php?

<td><%=HilightResults((WADALABEL1.Fields.Item("Item_number").Value), Request("S_Item_number"))%></td>