Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

convert asp code to php

Participant ,
Nov 30, 2007 Nov 30, 2007

Copy link to clipboard

Copied

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
TOPICS
Server side applications

Views

905
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 03, 2007 Dec 03, 2007
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($searchStrin...

Votes

Translate
LEGEND ,
Nov 30, 2007 Nov 30, 2007

Copy link to clipboard

Copied

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/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 30, 2007 Nov 30, 2007

Copy link to clipboard

Copied

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>

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 01, 2007 Dec 01, 2007

Copy link to clipboard

Copied

jim balthrop wrote:
> what about the search field part of the code in php?

That depends on the variables being used to hold the data. In principle,
though, it's this:

<?php echo highlightResults($dataValue, $searchString); ?>

Replace $dataValue and $searchString with the actual variables being used.

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 01, 2007 Dec 01, 2007

Copy link to clipboard

Copied

thanks David

here is what i have now
<?=$highlightResults[($row_WADpr_parts["mfg_name"].$Value), REQUEST("S_mfg_name")]?>

i get syntax error
Parse error: syntax error, unexpected ',', expecting ']' in C:\wamp\www\bellchemicalservice\pr_parts_Results.php on line 376

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 02, 2007 Dec 02, 2007

Copy link to clipboard

Copied

jim balthrop wrote:
> here is what i have now
> <?=$highlightResults[($row_WADpr_parts["mfg_name"].$Value),
> REQUEST("S_mfg_name")]?>

$ is used to indicate a variable. highlightResults() is a function, not
a variable. Parentheses are used for functions; square brackets for
arrays. You have also got a weird combination of pseudo-PHP and ASP
styles in there. At a guess, what you're trying to write is this:

<?= highlightResults($row_WADpr_part["mfg_name"],
$_REQUEST["S_mfg_name"]); ?>

However, in the interests of portability, I would suggest using the full
PHP opening tag with echo instead of the shorthand <?=, which isn't
supported on all servers:

<?php echo highlightResults($row_WADpr_part["mfg_name"],
$_REQUEST["S_mfg_name"]); ?>

$_REQUEST is a superglobal array that contains all the variables from
GET (passed through a URL query string), POST (from a form sent using
the post method), and cookies. If the information is always coming from
the same source, it's better to use the dedicated superglobal instead of
$_REQUEST. Replace $_REQUEST with $_GET for query string variables, or
$_POST for form variables.

A possible gotcha is a configuration setting known as "magic quotes".
Although magic quotes are now generally considered to be a bad thing,
and are due to be removed from the next version of PHP, most hosting
companies have magic quotes switched on. If magic quotes are switched
on, and the values passed through a query string or form are likely to
contain single or double quotes, you need to pass such values to a
function called stripslashes(). If that's the case, the code for a
variable passed through a query string becomes this:

<?php echo highlightResults($row_WADpr_part["mfg_name"],
stripslashes($_GET["S_mfg_name"])); ?>

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 02, 2007 Dec 02, 2007

Copy link to clipboard

Copied

thanks for your help David

here is where i am now with the following code
//function code
<?php

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

//and call function code
<td class="WADAResultsTableCell"><?php echo highlightResults($row_WADApr_parts["mfg_name"].$Value),$_GET["S_mfg_name"]; ?></td>

and i get this error message
Warning: Missing argument 2 for highlightResults(), called in C:\wamp\www\bellchemicalservice\pr_parts_Results.php on line 378 and defined in C:\wamp\www\bellchemicalservice\pr_parts_Results.php on line 184



Jim

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 02, 2007 Dec 02, 2007

Copy link to clipboard

Copied

jim balthrop wrote:
> the search produces the proper results, but the column 'mfg_name' does not
> print any value; on the results page that column is blank?

Is that because the function isn't doing the right thing, or because the
recordset doesn't produce a result? Have you tried it without the function?

<td class="WADAResultsTableCell"><?php echo
$row_WADpr_parts["mfg_name"]; ?> </td>

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 02, 2007 Dec 02, 2007

Copy link to clipboard

Copied

David

it is producing results from the recordset. results have 4 columns and all produce the correct value for each row.

without the function, it produces the correct value for each row, including 'mfg_name'

with the function as i have it now, the 'mfg_name' column produces this error for each row.
Warning: Missing argument 2 for highlightResults(), called in C:\wamp\www\bellchemicalservice\pr_parts_Results.php on line 378 and defined in C:\wamp\www\bellchemicalservice\pr_parts_Results.php on line 184

thanks for your help
Jim

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 02, 2007 Dec 02, 2007

Copy link to clipboard

Copied

jim balthrop wrote:
> with the function as i have it now, the 'mfg_name' column produces this error
> for each row.
> Warning: Missing argument 2 for highlightResults(), called in

Well, the error message is pretty clear. The second argument is missing
- or to be more precise, it has no value.

Your original ASP code uses Request("S_Item_number"). Where does that
value come from?

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 02, 2007 Dec 02, 2007

Copy link to clipboard

Copied

On Sun, 2 Dec 2007 01:08:29 +0000 (UTC), "jim balthrop"
<webforumsuser@macromedia.com> wrote:

> here is what i have now
> <?=$highlightResults[($row_WADpr_parts["mfg_name"].$Value),
>REQUEST("S_mfg_name")]?>


Should be:

<?php echo highlightResults($row_WADpr_parts["mfg_name"].$Value,
REQUEST("S_mfg_name")]?>

Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 02, 2007 Dec 02, 2007

Copy link to clipboard

Copied

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

the ("S_item_number") is the input name of the text field on the search page.

new development -
i was getting the missing argument 2 message on my testing server
so i put the page on line so you could view it and the value echos without the warning message; but does not highlight.
//this is the call function code that produces that result
<td class="WADAResultsTableCell"><?php echo highlightResults($row_WADApr_parts['mfg_name'].$Value), $_GET['S_mfg_name']; ?></td>


when i change to the call function code you suggested, i get the proper results, but no value prints under the 'mfg_name' column?

<td class="WADAResultsTableCell"><?php echo highlightResults($row_WADApr_parts['mfg_name'],stripslashes($_GET['S_mfg_name'])); ?></td>

to see on line go to
http://www.bellchemicalservice.com/homepage/service_searchparts.php
and put in advance in the MANUFACTURER text box. (NOTE- the strtoupper() does not seem to work; put in ADVancE and it will echo just like that.
also - put in VAC in the machine type and the value returned for 'mfg_name' is -1?

David, thanks for your help

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 03, 2007 Dec 03, 2007

Copy link to clipboard

Copied

jim balthrop wrote:
> when i change to the call function code you suggested, i get the proper
> results, but no value prints under the 'mfg_name' column?

Sorry, the return statement was missing from the function. It should
look like this:

function highlightResults($dataValue, $searchString) {
return 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/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2007 Dec 03, 2007

Copy link to clipboard

Copied

thanks again David

still not quite right - here is what i have now

//function code
<?php
function highlightResults($sDataValue, $sSearchString) {
return str_replace(strtoupper($sDataValue), strtoupper($sSearchString), '<span style="color:red;">'.strtoupper($sSearchString).'</span>');
}
?>

//call function highlightResults
<td class="WADAResultsTableCell"><?php echo highlightResults($row_WADpr_part["mfg_name"],stripslashes ($_GET["S_mfg_name"])); ?>

It now returns the input of the search text field highlighted in red, but it does not return all of the data in the 'mfg_name' column.
and when you search with any of the other search text fields, the return for column 'mfg_name' is '-1'

you can see this at
http://www.bellchemicalservice.com/homepage/service_searchparts.php
advance is the name of a manufacturer, so put in 'adva' in the MANUFACTURER box and see the return (i want it to return 'ADVANCE' in the manufacturer column with 'ADVA' highlighted in red).
do a new search, then put in 'buffer' in the MACHINE TYPE box and see the '-1' return in the manufacturer column.

jim

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 03, 2007 Dec 03, 2007

Copy link to clipboard

Copied

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/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2007 Dec 03, 2007

Copy link to clipboard

Copied

Thank you, David - I really appreciate your help
that did the trick
//used this as the function
<?php
function highlightResults($dataValue, $searchString) {
return preg_replace("/$searchString/i", '<span
style="color:red;">'.strtoupper($searchString).'</span>', $dataValue);
}

//and this is the call function
<?php echo highlightResults($row_WADpr_part["mfg_name"],
stripslashes($_GET["S_mfg_name"])); ?>

changed the ($_GET["to match the search text field"]

one last request - the results highlight the searchstring and put the searchstring in CAPS, but the datavalue is not in CAPS.
where should the strtroupper be placed to accomplish that?

What do you want for Christmas?
thanks again,
Jim Balthrop

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 03, 2007 Dec 03, 2007

Copy link to clipboard

Copied

jim balthrop wrote:
> that did the trick

Hooray!

> one last request - the results highlight the searchstring and put the
> searchstring in CAPS, but the datavalue is not in CAPS.
> where should the strtroupper be placed to accomplish that?

Rewrite the function like this:

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

> What do you want for Christmas?

Lots more people to buy my books! ;-)

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2007 Dec 03, 2007

Copy link to clipboard

Copied

I just bought PHP SOLUTIONS on Amazon

thanks again for your help
Jim Balthrop

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

jim balthrop wrote:
> I just bought PHP SOLUTIONS on Amazon

Thanks, Jim. I hope you find it useful.

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

LATEST
David Powers wrote:

> jim balthrop wrote:
>
>> I just bought PHP SOLUTIONS on Amazon
>
>
> Thanks, Jim. I hope you find it useful.
>
I think he may do so....
Mick

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines