Domanda

I have created the following code that prepends an ezproxy code to a link if it is not there already. I have 6 links on my page, 4 with the prepend already and 2 without. Adding the prepend to the 2 links without it works fine, but how do I then call the results to replace the links that do not contain the prefix?

Here is my page: http://lis7440.slis.wayne.edu/eh3343/final/electronic.php

I need to replace the ACP Pier and BioMed links with the array results. The code I am using to prepend is:

<?php



 $array = array("http://proxy.lib.wayne.edu/login?url=http://accessanesthesiology.mhmedical.com", "http://proxy.lib.wayne.edu/login?url=http://accessmedicine.mhmedical.com",
 "http://proxy.lib.wayne.edu/login?url=http://accesspharmacy.mhmedical.com", "http://proxy.lib.wayne.edu/login?url=http://accesssurgery.mhmedical.com", 
 "http://online.statref.com/Default.aspx?grpalias=MLC", "http://www.biomedcentral.com");



foreach($array as $value) {
    $pattern = '/^http?:\/\/proxy\.lib\.wayne\.edu\/login\?url=/';
    if (preg_match($pattern, $value)) {

    echo "<a href=$value>Database</a>";
    }
    else{
    $value = "http://proxy.lib.wayne.edu/login?url=".$value;

    }
    echo "<a href=$value>Database</a>";
    }
    ?>

How do I replace those 2 links (ACP Pier and BioMed in the paragraph section) with the new prepended array results links?

Thanks for any advice.

The entire code is:

<!<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<html>

<head>
<title>Medical Library</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="library.css" />


</head>

<body>
<div id="wrapper">

    <div id="header">
        <h1>Electronic Resources</h1>
    </div>




    <div id="maincontent">

    <div class="divimg">
    <img src="medical.png" alt="Medical">
    </div>





<p><a href="http://proxy.lib.wayne.edu/login?url=http://accessanesthesiology.mhmedical.com">AccessAnesthesiology (McGraw Hill)</a></p>

<p>In AccessAnesthesiology, physicians and residents can access a compendium of medical resources, including exclusive procedural videos, 
Custom Curriculum, and power search functionality, blended seamlessly with tables and charts designed for quick reference. Backed by an 
esteemed advisory board, AccessAnesthesiology offers multiple tools for resident education and certification/recertification in pain 
managements, critical care, and perioperative medicine.</p>

<p><a href="http://proxy.lib.wayne.edu/login?url=http://accessmedicine.mhmedical.com">AccessMedicine</a></p>

<p>A repository of medical knowledge from internal medicine, cardiology, genetics, pharmacy, diagnosis and management, basic sciences, 
patient care, and more. Continuously expanding, all databases in the repository contain the latest editions of selected medical titles.</p>

<p><a href="http://proxy.lib.wayne.edu/login?url=http://accesspharmacy.mhmedical.com">AccessPharmacy (AccessPharmacy)</a></p>

<p>Users can search over 20 core curriculum textbooks, identify a core topic, or browse site by organ system. Case studies, 
care plans, self-assessments and NAPLEX review help students develop and track key skills providing critical feedback for students and teachers. 
Other features include information on clinical relevance and lab tests, comprehensive drug database, news & updates from Pharmacotherapy News 
Network (PNN) and Goodman & Gilmans Pharmacological Basis of Therapeutics.</p>

<p><a href="http://proxy.lib.wayne.edu/login?url=http://accesssurgery.mhmedical.com">AccessSurgery (McGraw-Hill)</a></p>

<p>McGraw-Hill's AccessSurgery.com is an integrated online resource that provides medical students, surgical residents, and practicing 
surgeons with quick answers to surgical inquiries from trusted sources. Organized around the ACGME's (Accreditation Council for Graduate 
Medical Education) mandate for a Core Curriculum, AccessSurgery delivers content in context.</p>

<p><a href="http://online.statref.com/Default.aspx?grpalias=MLC">ACP Pier: The physician information and education resource (STATRef)</a></p>

<p>PIER is evidence-based clinical guidance presented electronically in a unique layered and telegraphic format. 
It is designed for rapid access to clinical information at the point of care. PIER includes recommendations based 
on all levels of medical evidence including RCTs, cohort and observational studies, case reports, and expert opinion.</p>

<p><a href="http://www.biomedcentral.com">BioMed Central (Biomed Central)</a></p>

<p>BioMed Central Ltd., an independent publisher in London, England, provides free access to biomedical research publications. 
These publications include biology and medicine journal articles, current reports, and meeting abstracts. BioMed Central offers
 information about current controlled trials, as well as topics in modern biology.</p>

 <?php



 $array = array("http://proxy.lib.wayne.edu/login?url=http://accessanesthesiology.mhmedical.com", "http://proxy.lib.wayne.edu/login?url=http://accessmedicine.mhmedical.com",
 "http://proxy.lib.wayne.edu/login?url=http://accesspharmacy.mhmedical.com", "http://proxy.lib.wayne.edu/login?url=http://accesssurgery.mhmedical.com", 
 "http://online.statref.com/Default.aspx?grpalias=MLC", "http://www.biomedcentral.com");



foreach($array as $value) {
    $pattern = '/^http?:\/\/proxy\.lib\.wayne\.edu\/login\?url=/';
    if (preg_match($pattern, $value)) {

    echo "<a href=$value>Database</a>";
    }
    else{
    $value = "http://proxy.lib.wayne.edu/login?url=".$value;

    }
    echo "<a href=$value>Database</a>";
    }
    ?>


</body>
</html>
È stato utile?

Soluzione

You just need to add the second echo inside the IF

$array = array("http://proxy.lib.wayne.edu/login?url=http://accessanesthesiology.mhmedical.com", "http://proxy.lib.wayne.edu/login?url=http://accessmedicine.mhmedical.com","http://proxy.lib.wayne.edu/login?url=http://accesspharmacy.mhmedical.com", "http://proxy.lib.wayne.edu/login?url=http://accesssurgery.mhmedical.com", "http://online.statref.com/Default.aspx?grpalias=MLC", "http://www.biomedcentral.com");

foreach($array as $value) {
$pattern = '/^http?:\/\/proxy\.lib\.wayne\.edu\/login\?url=/';
    if (preg_match($pattern, $value)) {
        echo "<a href=$value>Database</a>";
    }
    else{
        $value = "http://proxy.lib.wayne.edu/login?url=".$value;
        echo "<a href=$value>Database</a>";
    }
}

Edit added PHP soluition with dummy database

<?php

$resources = array();
// Add Resources to Array (fake DB)
array_push($resources, array(
    'link' => 'http://proxy.lib.wayne.edu/login?url=http://accessanesthesiology.mhmedical.com',
    'title' => 'AccessAnesthesiology (McGraw Hill)',
    'text' => 'In AccessAnesthesiology, physicians and residents can access a compendium of medical resources, including exclusive procedural videos, 
    Custom Curriculum, and power search functionality, blended seamlessly with tables and charts designed for quick reference. Backed by an 
    esteemed advisory board, AccessAnesthesiology offers multiple tools for resident education and certification/recertification in pain 
    managements, critical care, and perioperative medicine.'
));

array_push($resources, array(
    'link' => 'http://proxy.lib.wayne.edu/login?url=http://accessmedicine.mhmedical.com',
    'title' => 'AccessMedicine',
    'text' => 'A repository of medical knowledge from internal medicine, cardiology, genetics, pharmacy, diagnosis and management, basic sciences, 
    patient care, and more. Continuously expanding, all databases in the repository contain the latest editions of selected medical titles.'
));

array_push($resources, array(
    'link' => 'http://proxy.lib.wayne.edu/login?url=http://accesspharmacy.mhmedical.com',
    'title' => 'AccessPharmacy (AccessPharmacy)',
    'text' => 'Users can search over 20 core curriculum textbooks, identify a core topic, or browse site by organ system. Case studies, 
    care plans, self-assessments and NAPLEX review help students develop and track key skills providing critical feedback for students and teachers. 
    Other features include information on clinical relevance and lab tests, comprehensive drug database, news & updates from Pharmacotherapy News 
    Network (PNN) and Goodman & Gilmans Pharmacological Basis of Therapeutics.'
));

array_push($resources, array(
    'link' => 'http://proxy.lib.wayne.edu/login?url=http://accesssurgery.mhmedical.com',
    'title' => 'AccessSurgery (McGraw-Hill)',
    'text' => "McGraw-Hill's AccessSurgery.com is an integrated online resource that provides medical students, surgical residents, and practicing 
    surgeons with quick answers to surgical inquiries from trusted sources. Organized around the ACGME's (Accreditation Council for Graduate 
    Medical Education) mandate for a Core Curriculum, AccessSurgery delivers content in context."
));

array_push($resources, array(
    'link' => 'http://online.statref.com/Default.aspx?grpalias=MLC',
    'title' => 'ACP Pier: The physician information and education resource (STATRef)',
    'text' => 'PIER is evidence-based clinical guidance presented electronically in a unique layered and telegraphic format. 
    It is designed for rapid access to clinical information at the point of care. PIER includes recommendations based 
    on all levels of medical evidence including RCTs, cohort and observational studies, case reports, and expert opinion.'
));

array_push($resources, array(
    'link' => 'http://www.biomedcentral.com',
    'title' => 'BioMed Central (Biomed Central)',
    'text' => 'BioMed Central Ltd., an independent publisher in London, England, provides free access to biomedical research publications. 
    These publications include biology and medicine journal articles, current reports, and meeting abstracts. BioMed Central offers
     information about current controlled trials, as well as topics in modern biology.'
));

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<html>

<head>
<title>Medical Library</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="library.css" />


</head>

<body>
<div id="wrapper">

    <div id="header">
        <h1>Electronic Resources</h1>
    </div>

    <div id="maincontent">

    <div class="divimg">
    <img src="medical.png" alt="Medical">
    </div>


<?php foreach ($resources as $resource) : ?>

    <?php 
    $pattern = '/^http?:\/\/proxy\.lib\.wayne\.edu\/login\?url=/';
    if (!preg_match($pattern, $resource['link'])) $resource['link'] = "http://proxy.lib.wayne.edu/login?url=" . $resource['link'];
    ?>

    <p><a href="<?php echo $resource['link']?>"><?php echo $resource['title'] ?></a></p>

    <p><?php echo $resource['text']; ?></p>

<?php endforeach; ?>

</body>
</html>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top