Jump to content

surfwtw

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

surfwtw's Achievements

Member

Member (2/5)

0

Reputation

  1. Yeah the only solution I have found is only replace once and then go to my database, copy and paste the filename above the file as if it is an image title. That way if a word is being replaced it won't ruin the file. I have spent days searching trying to figure this out. I have a code that works to search and replace words to make them bold and it doesn't change the file name, it also works for linking the word but I haven't figured out a way to manipulate it so that it works for a large array of words. The code is below, if anyone can figure out how to get it to work for an array of more than one word then please let me know. Look at the code below, what if instead of replacing "$word" with "<b>$word</b>" I wanted to replace (car, truck, boat) with (<b>car</b>,<b>truck</b>,<b>boat</b>. All I know is that THIS CODE did not corrupt my files. It only changed the word when it appeared in text. <?php function boldWord($word,$definition){ $word = strtolower($word); $ucf_word = ucfirst($word); $uc_word = strtoupper($word); return str_replace(array($word,$ucf_word,$uc_word), array("<b>$word</b>","<b>$ucf_word</b>","<b>$uc_word</b>"), $definition); } $text = "$definition"; echo boldWord("$word",$definition); ?>
  2. I am wanting to replace certain words to make them bold and also linked. The code below is working however it is also replacing images that have the same filename therefore causing the image to be broken. How can I replace the word when it appears without replacing the filename when it appears. <?php $find = array ("/$word/i","/A Duty of Care/i"); $replace = array ("<a href=/link.php?word=$word><b>$word</b></a>","<a href=/link.php>A Duty of Care</a>"); Echo preg_replace ($find, $replace, $definition); ?>
  3. I want key words on my website to be linked for efficiency reasons for my customers and for SEO purposes. When people are reading an article and they come across a word they don't know, I want it to be linked the way they are in wikipedia.
  4. Yes that worked. The only problem is that I actually have thousands of links Thanks
  5. Below is the code I have so far for only 2 terms with '$word" being the keyword of the site and all the other words are suppose to be linked if they appear in the text. Okay I have thousands of different possible words from the same table. In the table 'word' is the term to be defined and 'definition' is the main content. I want a code that recognizes any word that is listed in my table and replaces it. <?php $find2 = array ('/$word/i', '/bond/i'); $replace2 = array ('<a href=http://www.subjectmoney.com/definitiondisplay.php?word=$word><b>$word</b></a>', '<a href=http://www.subjectmoney.com/definitiondisplay.php?word=Bond>bond</a>'); Echo preg_replace ($find2, $replace2, $definition); ?>
  6. WOW THANKS. That is so much more simple than the code I was using before. OKay, is there any way I can also make it a link?
  7. I am using preg_replace to automatically bold "$word" when it appears. It will only replace the word when capitalized. How can I get it to replace the word without being case sensitive. Also could I also throw a link in? I tried and I get a syntax error. I'm guessing the links in PHP are different than HTML Here is my code <?php $find ="/$word/"; $replace ="<b>$word</b>"; Echo preg_replace ($find, $replace, $definition); ?> Thanks
  8. OK I am definitely having problems and I appreciate all the help. I am already connected with the code below <?php // Use the URL 'word' variable to set who we want to query info about $word = $_GET['word']; // filter everything but numbers for security if ($word == "") { echo "Missing Data to Run"; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM dictionary WHERE word='$word' LIMIT 1"); $count = mysql_num_rows($sql); if ($count > 1) { echo "There is no user with that id here."; exit(); } while($row = mysql_fetch_array($sql)){ $word = $row["word"]; $definition = $row["definition"]; $equation = $row["equation"]; $example = $row["example"]; $keywords = $row["keywords"]; $related_words = $row["related_words"]; $name = $row["name"]; $email_address = $row["email_address"]; $site = $row["site"]; } ?> And below is the code that I use to pull out the text to display. I have a code that automatically bolds the "word that is being defined" but I also want to add a code that finds certain words and links them to their definitions. <?php function boldWord($word,$definition){ $word = strtolower($word); $ucf_word = ucfirst($word); $uc_word = strtoupper($word); return str_replace(array($word,$ucf_word,$uc_word), array("<b>$word</b>","<b>$ucf_word</b>","<b>$uc_word</b>"), $definition); } $text = "$definition"; echo boldWord("$word",$definition);?>
  9. What does $run do? Am I supposed to change that to something or do I leave it the same? Thanks
  10. Anon-e-mouse Do you have an example that I could play around with. I am familiar with the PHP concept but not fluent with the coding.
  11. I have the following code which automatically bolds the "word" that is being defined. Is there a way that I could manipulate this code to make it link words other than the "word"? function boldWord($word,$definition){ $word = strtolower($word); $ucf_word = ucfirst($word); $uc_word = strtoupper($word); return str_replace(array($word,$ucf_word,$uc_word), array("<b>$word</b>","<b>$ucf_word</b>","<b>$uc_word</b>"), $definition); }
  12. Yeah that could be a problem but luckily my website is a finance website so the words are complex. BTW I plugged that code in and it didn't do anything. Not sure why.
  13. Well my goal is to have it crawl the content on the display page and if the word is there it will turn it into a link. I have over 1000 definitions and I want there to be links to the url whenever one of the words appears. This means that I would probably have to list a code for every word that I have content for but that would be better than physically reading and locating the words and then adding links. The display page is only one page that displays many different pages of data so say I clicked on the definition for "trailer" and the word "car" appeared then I would want to be able to click on "car" and have a new page open up with the definition of "car". Obviously I would have to repeat the code for every word I wanted to be linked.
  14. I have a website that has definitions and articles. I need a code that craws the php content pulled from my database, finds a specified word and replaced that word with a link. For example If "car" appears replace with <a href="http://www.website.com/car.php">car</a> Thanks Todd
  15. Here is the code. "$word" is the word that I want to be bold. "$definition" is all the content that is being displayed. When "$word" appears in the content ($definition) I want "$word" to be bold. Thanks <h2><b>Definition of <?php echo "$word";?></b></h2> </td> </tr> <tr> <td cellpadding="5"> <?php echo "$definition"; ?> </center></br></br>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.