Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 1st, 2007, 01:37 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default inserting text in the middle of a paragraph o text

HI everyone-

I am trying to add a line of text into a paragraph of text that is coming from a sql database.

for example If I had the following paragraph:

[u]Oh, when you walk by every night
Talking sweet and looking fine
I get kinda hectic inside
Mmm, baby I'm so into you
Darling, if you only knew
All the things that flow through my mind</u>


I want to add "[ found on mysite.com ]" to the middle like:

[u]Oh, when you walk by every night
Talking sweet and looking fine
I get kinda hectic inside
[ found on mysite.com ]
Mmm, baby I'm so into you
Darling, if you only knew
All the things that flow through my mind</u>

any help would be appreciated greatly
Reply With Quote
  #2 (permalink)  
Old September 5th, 2007, 02:49 AM
Authorized User
 
Join Date: Sep 2007
Location: , , .
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default

$part1 = intval((strlen($string) /2));
$part2 = -(strlen($string) - $part1);

$part1Text = substr($string,0,$part1);
$part2Text = substr($string,$part2);

...im sure you can take it from here:)



http://mynameissteve.com
Reply With Quote
  #3 (permalink)  
Old September 5th, 2007, 03:06 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not sure I follow that. My php skills aren't that great, but I know the basics... would you be real mad if I asked you to explain a little more:)

Thanks
Reply With Quote
  #4 (permalink)  
Old September 5th, 2007, 03:18 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I spoke too soon, I was able to make it work with your code...thanks so much. It appears to sometimes cut off words though in the middle, is there a way to tell it to go to the end of that line?

Thanks Again
Reply With Quote
  #5 (permalink)  
Old September 5th, 2007, 07:40 PM
Authorized User
 
Join Date: Sep 2007
Location: , , .
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default

I got your email from earlier...I will look at the code to make it do that later tonight:)

http://mynameissteve.com
Reply With Quote
  #6 (permalink)  
Old September 5th, 2007, 11:42 PM
Authorized User
 
Join Date: Sep 2007
Location: , , .
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ok totally rewritten and I added some comments

<?

$string ='test this string sentence';

//break string into an array or words
$words = explode(' ',$string);

//get the total number of words in your string
$num_words = count($words);

//declare variable
$first_string = '';

//divide the total # of words by two
$end_of_first_string = ($num_words / 2);

//loop up until the first half
for($i = 0; $i < $end_of_first_string; $i++){
    $first_string .= $words[$i] . ' ';
}

//declare variable
$second_string = '';

//fmod is used to find the reminder of a division statement
//this is need if the # of words happen to be odd
//otherwise it would print the middle most word twice
if(fmod($num_words,2) == 1){
    $start_of_second_string = ($end_of_first_string + 1);
} else {
    $start_of_second_string = $end_of_first_string;
}

//loop to end of words
for($i = $start_of_second_string ; $i < $num_words; $i++){
    $second_string .= $words[$i] . ' ';
}

//do what you need to do here with the variables ;)
echo($first_string .' some filler text '.$second_string);


?>

http://mynameissteve.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
body text not inserting Jamessaep BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 April 14th, 2008 02:45 PM
Problem inserting multilingual text into database salim C# 0 May 5th, 2007 11:11 AM
Inserting text file lines into an array? georginho Visual Basic 2005 Basics 8 January 15th, 2007 09:44 AM
bcp - inserting quoted text epicurean SQL Server 2000 0 April 24th, 2006 10:58 AM
Inserting text from datagrid into Memo field in c# kgriffin Classic ASP Databases 0 May 4th, 2005 10:17 AM



All times are GMT -4. The time now is 05:09 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.