First time working with PHP.

Hello, this is my first attempt with PHP, I am fairly familiar with html and know a little js. but I am trying to figure out how to have an external page with an array of lines (sentences) and be able to pull specific lines from it from elsewhere on a webpage.
From what I was reading on a tutorial site I came up with this script for the external page, it may be wrong I don’t know:

Lines.php

<?php $Line[1]="sentence 1 here."; $Line[2]="sentence 2 here."; ?>

then I believe I need to add an include into the page I want to pull the lines into.

<?php include("Lines.php"); what I'm having trouble with is echoing the sentence onto the page. I would also like to have some sort of a search function where I will have a pull down to select chapters and they select the line(s) and it will display them. Thanks for any help, I amy even be barking up the totally wrong tree, not sure.

Hi,

With your $Lines array, you may try this:

echo $Lines[1];

This should display any given value for key 1, which in your case is “sentence 1 here”. You can also perform search within your array using this function:

array_search(search_string, array).

This function searches through your array and returns the array key based on your search key.

I’ve tried just plain echo it and I get an error message, here is a sample of what I’m trying:

Lines.php (containing all my arrays)

< ?php (space added so it doesn’t think I’m trying to put the code here)
$Line[1]=“Sentence 1 goes here.”;
$Line[2]=“Sentence 2 goes here.”;
?>

WebPage.php (the page I want the specific line echoes on)

< ?php
echo $Line[1] . " " . $Line[2];
?>

This is the error message I get:

Parse error: syntax error, unexpected T_ECHO in C:\wamp\www\Webpage.php on line 2

Works perfectly fine for me.

I figured it out, I have the include(“Lines.php”) but I forgot to end it with a ;

Sponsor our Newsletter | Privacy Policy | Terms of Service