Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Breaking Strings?


I have a string (actually 100's of these, but lets take one):

$string ="TI: Some journal title AU: SomeAuthor,-S; Smith,-A; Jones,-B SO: SomeSource. 2002 Jan 9; 287(2): 188; discussion 189-90 JN: Some Journal Title";

This needs to be turned into an array:

$entry = array(
'Some Item Title',
'SomeAuthor,-S; Smith,-A; Jones,-B',
'SomeSource. 2002 Jan 9; 287(2): 188; discussion 189-90',
'Some Journal Title');

As you can see, each array item should be defined by what comes after either/all of the following: 'TI:' 'AU:' 'SO:' 'JN:'

So, I need to be able to create a pattern that can look through the string and return everything in between TI: and AU:, then AU: and SO, etc.

for example:

eregi(???, $string, $entry);

I'm fairly new to this and can't seem to figure out the regex I need for the pattern. Is this even the way to go about it?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Breaking Out Of An Iframe
I cannot figure this one out. My script is being displayed in an iframe (a wiki page) and I have one option won't give me the correct results unless the page is displayed in either

a) new tab in NS browser
b) new browser instance.

The option in question is used to print forms, and I use the browser Print Preview for the page setup. It's all pretty useless if I have the page and iframe content in my preview.

I thought using header() would do the trick.

Breaking A Page Down.
What is the best solution to break down a php page into certain section using MySql, For example i'm looking at designing a page that reffers to a MySQL database that contains the html code for the navigation. So that in future if the navigation changes I'll only need to changed the html code in the database and all the pages will be sorted. I'm also looking at doing the same for the information on the footer of the page, with teh contact details.

Breaking Out Of Quotes
I know I can use stuff like in front of " so that it can't break out of a "" and start doing bad things, but it seems there are other situations where, E.G., if the string is hex for " then it has the same effect, and stuff like that, and it gets tricky escaping it all, so I'm wandering, is there some kind of option I can enable or extension I can install that just simply prevents objects/variables/arrays from breaking out of single/double quotes and also for mysql queries?

And also for html so E.G. echo"<img src='$asdf'>"; can't be exploited to do other things? I don't care if it isn't free as long as it works good and isn't to expensive..

Breaking Up Querys
I have a page that updates a table every workday. (these are standard updates, like if someone has moved, or has a different phone number or something.)  It is too big of a query to run the entire table all at once, so it is split out. 

The split is grouped by the first letter of a first name field.  Right now it is broken up into 5 parts, and each part has a group of letters (i.e. "a" to "d" is one group, "e" to "k" is the next, and so on.  As you can see, these do not have an even number of letters, but that is because some letters have a lot more entries, and need to be in smaller groups.) 

The reason it is split out into 5 groups is that I can run one group on each workday (Monday through Friday), and I can have the PHP check what day of the week it is.  (I use a case statement, the first case is for Monday, the second is for Tuesday, etc.) Code:

Breaking A Loop.
I have one going through rows of a sql database until it matches some data with user input. I need to put a break command in there but can't seem to find out how to achieve this.

Breaking Rows
I am using a while statement to pull results from my database. Now if I have like 40 results how would I make it break into rows.

So instead of;

result result result result result result result result result result result result result result result result result result

I want;

result result result result result
result result result result result
result result result result result
result result result result result

XML Parser Breaking Up URLs
I'm having a problem parsing an xml file in which one of an elements character data is a url which contains multiple "&" characters. For some reason the parser breaks up the data into multiple pieces. For instance, when I call this function(abbreviated):

function characterDataHandler ($parser, $data)
{
global $element;
global $url;
if ($element == "URL") {
$url = $data;
echo "url=".$url."<br>";
}
}

I get some output like this:


url=http://www.somewebsite.com/index.jsp?s=af

url=&

url=filter=1

url=&

url=show=all


Do urls with querystrings have to be handled differently then regular character data?

For Loops Breaking At A Certain Multiple
Can someone help me out with writing a script that will make will loop 500 times, but at every 4th multiple, it will insert a peice of code?

I tried all day to get this, and so far, nothing has worked.

Characters Breaking My Query
Im using encrypted data to store cc info. The PHP code encrypts and sends the result to the database. the problem is that the encrypted string contains lots of characters that will break my sql query. I can do a replace but there are lots of characters.

for example, a character will look like this:

g%$^'GDF$%^//"@#$%/||''$#"/|#dfsa.

how can I put this information in a different format... and then retrieve the data to decrypt the string?

Not Breaking Loop In Function
I get this error: <b>Fatal error</b>: Cannot break/continue 1 levels in <b>file.php</b> on line <b>128</b><br>

This happens when I call a function. In the function there is a break; This is cause the break is in a function and not in the loop. But it gets called inside the loop. Is there a fix for this?

E-Mail Not Breaking Lines
I'm sending an e-mail via a contact form, but somehow the lines aren't breaking in the text, it always looks like this:

lorem ipsum

dolor

sit

amet

lorem


Which is of course not readable at all. What am I doing wrong here? I'm using a few security checks and such for cleaning the field up; $text = trim($text);
...
$text = stripslashes(strip_tags($text));
...
$text = mysql_real_escape_string($text);
.....

#and then the part where it's included in the message:
$message .= "Nachricht: {$text} ";

Can any of those be causing the display problem?

Script Breaking On Mysql_result
I was trying to figure out why one of my scripts was failing and by using an "or die" statement for the SQL narrowed it down to this bit of code:

$md5 = md5_file("swf/" . basename($jpg_link));
$dupe = mysql_result(mysql_query("select count(gId) from games where gSwfFile='$md5.swf"), 0);
if(!empty($dupe))
{
continue;
}

This is giving the following error - "Warning: mysql_result(): supplied argument is not a valid MySQL result resource"

The thing is, I've checked that SQL query by running other values in place of $md5 through it and it appears to be fine. 

select count(gId) from games where gSwfFile='Flat War july 30th 2007.swf';
Any ideas?

Header Function - Breaking Out Of A Frame
I can create a plain htm link and have the new page break out of frames. a href='page.html' target='_top' Can this be done with a Header redirect in php?

Breaking Backwards Compatibility - Good Or Bad?
If you have any PHP scripts which will not work in the current releases
due to breaks in backwards compatibility then take a look at
http://www.tonymarston.net/php-mysq...everything.html and see if
you agree with my opinion or not.

Breaking Survey Into Seperate Parts?
I have a very long survey form with 4 different sections. Is there anyway with php to split this form into 4 popup windows so the person can click on the section they wish to fill out and when they are done, go back to the host survey form and continue on? I know there must be a way to do it, i'm just at a loss as to how i would pass the variables off? Cookies perhaps?

Breaking Up A Comma Seperated List
i have a list seperated by commas: 1. 3. 5. 7. 9 actually is a varible

$members ="1, 3, 5, 7, 9"; what would be the best way to break that up to insert the values into a table in a loop.

Breaking Up Text For Multiple Pages
I was recently put in charge of heading up my company's website, and
while I have a lot of experience on the design side of things, I'm
still very new to the programming side. When I started, the website had
just gotten a revision, but the site was an utter mess, so I've been
trying to fix it up. As I've gone along, I've learned some aspects of
PHP, but my knowledge is still very limited.

Here is the problem I'm trying to fix. A backend is used to enter
information into our MySQL database, and then a page template pulls it
out to make the page. For our reviews, the PHP coding currently breaks
up the review's text so that it can be places across multiple pages.
The problem is, the way the text breaking was set up, the end of one
page and the beginning of the next are totally chaotic, with breaks
often coming mid-sentence.

Here is what I'd love: other coding automatically puts an HTML break at
the end of paragraphs, and then another in the space between one
paragraph and the next. I'd love to have the code search for when those
double breaks come up, and then break up the text after, say, every
sixth pair of HTML breaks. I'd also like the option to break the text
myself by putting in some sort of text code in the original text. At
this point, though, anything that can make the breaks more elegant
would be a huge improvement.

I really appreciate any help anybody can give me in this one. Please
remember that I know very little of PHP, and I'm not much of a
programmer anyhow, so things that you may take for granted that people
would understand about PHP, I might not know.

I tried to pull out what I thought was the current coding for the text
break. Here it is. I'd also like to get rid of the part1/part2 factor.
Before, they had the text breaking to help in fitting into the layout
around an image, but I've fixed that so I no longer need the break. So,
that portion no longer needs to be a factor.

if ($page == ""){
$page = 1;
}
$no_letters = strlen($Game_Full_Story);
$times = ($no_letters / 3800) +1;
$Game_Full_Story = wordwrap($Game_Full_Story,3800,"*#^");
$Game_Full_Story = explode ("*#^", $Game_Full_Story);
$pages = array();
for ($i=0; $i<$times ; $i++){
$part[$i] = $Game_Full_Story[$i];
if ($i != 0){
array_push($pages, $i);
}
}
$page = $page-1;
$story = $part[$page];
if (strlen($story) < 460){
$parts1 = $story;
}else{
$story = wordwrap($story,460,"*#^");
$story = explode ("*#^", $story);
$parts1 = $story[0];
$count = count($story);
$parts2="";
for ($i=1; $i<$count; $i++){
$parts2 .=$story[$i];
$parts2 .=" ";
}
}

Breaking Up A String Into Individual Words
I have a text box that I will use to search a database. I would like
to use it so that it will not use a whole string (ie. 'red striped
top') but instead break it up into individual words (ie. 'red',
'striped', 'top') and maybe put it into and array. I will then use the
words in the array to search the database.

How do I break a string up this way?

Also, is this the most common way of creating a means of searching a
database?

Breaking Up The Query String Dynamicly?
using $Get_string = $_SERVER['QUERY_STRING']; to receive a query string such as
month=may&$day=15&year=2006

so that $Get_string = "month=may&$day=15&year=2006"

can I separate the values and turn them into variables? (like a normally would with a url get)

$month = "may"
$day= "15" etc

it would be great to just do $_GET on the url but I'm sending the string as a variable to another script... so i can't just go the easy route.

Breaking The BACK Button (Refresh Problem)
I have a php page which serves up multiple pages based on how the user
interacts with it - there are links on the first page that will reload (from
the same php file) a new page with form fields and submit buttons, and when
a user posts from that new page (or cancels), then the same php file is
again loaded, detecting how the user responded and generating the
appropriate html for whatever should be none next. All very typical.

What I want to know is, is there a way so that once a user has posted from
some submit button from one page (we'll say he Cancel's from a page that had
a form Cancel button so he returns to the original non-form default page
generated from the php file), can it be made so if the user then "refreshes"
the new page (hits the Refresh or Reload browser button) he does NOT get the
browser's "The page cannot be refreshed without resending the information.
Click Retry to send the information again, or click Cancel to return to the
page that you were trying to view." dialog? In other words, what I'd like is
a way to have the browser think that there was no posting done (even though
there was) once I've generated this certain 'home' page with my php code, so
that user ReLoad's of the page won't get this warning.

This is probably related also to problems I've had with "breaking the BACK
button" on sequences of php pages: if the user BACK's up to a page that was
generated by a post, it may not even be possible to regenerate the original
page.

Return Data Breaking Input Field
My return data is: (I have nothing to do with how the og person choose to input this)

<font color="#800080">CASE</font>

and I am setting the value of a input text form field equal to that return

$input      = "<input type="text" name="queOpt". $i ."" value="". $this->_queArr[$i] ."" />";

im lost on how to fix this. addslashes doesnt make sense  - maybe it is the double quote thing

Strings And {...}
Is there something build into php where {0} or {1} means something?

For example,

SELECT * FROM table1 WHERE col1 = {0} AND col2 = {1};

Strings
in my db i have dates stored like dd/mm/yyyy. how can i split the string up to get date = dd month = mm and year = yy. This is so i can then get an array on the month so it can show dd [month name] yyyy

Joining Two Strings Into ONE?
I have no idea on how to joining two strings into ONE.
eg.
$str1 = "Hello ";
$str2 = "World.";

I want to make a string
$str3 = "Hello World.";

Combining Strings
Say I wanted to take three string variables,

$one = "123"
$two = "abc"
$three = "easy as"

, and combine them into a single variable:

$combined = "easy as abc 123"

I've looked over the implode function, but I'm not sure how to arrange the statement..

$combined = implode("", $one, $two, $three)

Returns an error "Wrong parameter count for implode() in test.php3"

Preg_replace With Strings
I have the following text:

------------
<A HREF="http://www.webwater.de/single.php4?top=unscribe&sub=123-@f.gruber&langr=de">hier</A>
------------
now i want to replace this with:
------------
hier
------------
but "123-@f.gruber" is variable.
I tried this one, but is dosn't work:

$repf = "<A HREF="http://www.webwater.de/single.php4?top=unscribe&sub=";
$repl = "&langr=de">hier</A>";
$bodyde = preg_replace ("/$repf.*/$repl", "hier", $bodyde);

Sorting Strings!
Hi

I need to read a .txt file and sort the value, highest firs, lowest last.

The .txt file contains the following info on a different row:
altavista:joe:5
yahoo:eric:2
disney:dis:4

the firs thing i did was reading the first line and split the code by ":" so that
echo $referrer[0] //would give altavista
echo $referrer[1] //would give joe
echo $referrer[2] //would give 5

I want to sort these lines on the numbers(highest first, lowest last) and print this in a table. How can i do this?
so what i would like in a table is this

<table>
<tr><td>
altavista</td><td>5</td></tr>
<tr><td>
disney</td><td>4</td></tr>
<tr><td>
yahoo</td><td>3</td></tr>
</table>


Is this possible anyway?

Can Php Concat Strings?
Can php concat strings, it's not a fuction listed on the php site? what would the format be like, $output concat($str1, $srt2).

Query Strings
How do you get the value you pass from one page as part of the query string i.e

htttp://www.somesite.com/postage.pgp?newsid=2

How you you get the value of the variable in the next page, stumped.

Prepare Strings For XML
I was just wondering if anyone was aware of any prebuilt functions that would prepare strings for 'well-formed' XML. I.E. There is obviously a lot of various characters that do not work with 'well-formed' XML (&,$, etc.). I am looking for a pair of functions like stripslashes|addslashes; urlencode|urldecode.

Two Equal Strings?
I was just checking php.net but couldn't find a function that will compare to strings.

Did I just overlook it? or do I have to write a function to compare the two stirngs in php?

If there is a function, which one is it?
If there isn't a function, could you give me an idea of the coding that would compare two strings?


Query Strings
I have got query stings up and working on my site. But there are some problems. How do I make the title of the page change with the diff. index.php?page=

Also, I wanted the query strings to act like a frame, so when clicked it only changes the content, not the whole page.

I am using this code:
[PHP
<?php

if ($page=="whatever") {
include ("whereat");
}

elseif ($page=="whatever") {
include ("whereat");
}

elseif ($page=="whatever") {
include ("whereat");
}

else {
include ("whereat");
}

?>
[/PHP]

Appending Strings
How would I build up a string so that i get

$variable1 dynamically which should be used in a sql query like:

$sql = mysql_query("INSERT INTO **** (var) VALUES('$variable1');

the problem is that i need to run this 30 times and therefore need to create the $variable1, $variable2 etc on the fly - my problem is I cant get it working with my strings. Im using $i as integer in a loop. Tried things like
'$variable.$i' this wont work since i get the value .1 inserted.

How To Get Strings With Spaces?
I have a Select pop-up with list of country names with a variable $Country. I pass this variable using the URL to the next page and it displays fine. When I have a link from page two to page three, the Variable is cut after a space.
(e.g) Page one I select "United States of America". Page 2 shows it ok. But, on page 3 this variable is only "United" the rest is gone. here is the link i use:

<a href="Response5.phtml?Country=$Country&day=$day&month=$month&year=$year">$day</a>

Query Strings
I've been working on a script for a while now and have run into a problem. I'm using a function to spread out my guestbook entries throughout a few pages, however, when I add a query string into the equation it doesn't want to work, what I'm guessing is that a query_string call won't work in a function as it will everywhere else. PHP Code:

Query Strings
I use query strings like this: mypage.php3?q1=query1&q2=query2

Then I can use them as variables: $q1 = query1 / $q2 = query2

This works fine. I have seen sites that do it like this: mypage.php3/q1=query1/q2=query2/
How?

Formatting Strings?
i have a row in one of my databases, and i use a timestamp to imput the current time into the row. Now, when i output the timestamp i get something like 20001218155634. I tried reading the php manual to help me on editing strings, but it wasn't of much help.

So does anybody know any websites with good php string manipulating tutorials? or can anybody show me how to format the timestamp?

Joining Strings
I must be doing something wrong, but I can't see it. I an trying to build a long string that is to be a mail message, but I keep getting an error. PHP Code:

Switching Strings?
I want to be able to switch a certain word in a string with one that is in an associated array( is that right?). Here is an example: PHP Code:

Strings To Lowercase
I want to convert a URL typed in /ANyCAsE/ to /lowercase/ - the following does work if the URL is lowercase already but not if mixed or upper case. What is incorrect?

<?php
$url_array=explode("/",$REQUEST_URI);
$url_category_type=$url_array[1];
$str = strtolower($url_category_type);
print $str;?>

Parsing $ In Strings
I've got a file that has $str in it. I read the file into a string ($str is initialized). my question is, whether $str will be parse (replaced by it's value). If not, how can achive this.

Form Strings
i have a form, and the php script should populate the form with the values selected from the db, but it doesnt. PHP Code:

Alphanumeric Strings
Is there a way to check if a string only contains letters or numbers, and not using the ctype_alnum function?

Strings And Conditionals..
trying to learn strings... I'm a bit mystifed about
something.. how do you test for conditions in strings? for example,
how would you do what in JavaScript (or Java) you do like this

if (email.indexOf('@') != -1) { // etc..

also how do you test for length of a string? I tried:

if (strlen($myName) == 7) {

but got error...

I have looked at sections dealing with conditionals in tutorials, but
don't see examles of this (also don't see functions like indexOf(),
etc.. under Strings here, http://us2.php.net/manual/en/ref.strings.php..

How Does PHP Store Strings?
I've been told that PHP strings are null terminated. If PHP strings
are in fact null terminated, I'm a bit puzzled how the following code
can work:

$filename = 'ucs2_file.txt'
$contents = file_get_contents($filename);
echo "Echoing file contents";
echo $contents."";

The HEX contents of the file are as follows:

FE FF 00 61 00 62 00 63 00 64

FE FF is the byte order mark, 00 61 is the character 'a' encoded in
UCS-2, 00 62 is the character 'b' encoded in UCS-2, and the next two
characters in the file are 'c' & 'd' (encoded in UCS-2) represented by
00 63 and 00 64 respectively.

So, file_get_contents reads the file contents into the string. So I'm
quite sure that after the function call, $contents points to an area
of memory that stores the bytes that were in the file; FE FF 00 61 00
62 00 63 00 64.

On the assumption that strings are null-terminated in PHP, I'm
guessing that the echo function is implemented something like (in
pseudo-code):

while($currentByte != NULL)
{
printByte($currentByte);
$currentByte = getNextByte($currentByte);
}

In otherwords, the NULL character tells the function when the end of
the string has been reached. So why, if strings are in fact null
terminated in PHP, does the echo function NOT stop when reaching the
third byte in the aformentioned byte sequence? How does it know that
there are more bytes in the string after the NULL byte? This behaviour
leads me to believe that strings in PHP are something more than just
null-terminated byte sequences in PHP.

Cropping Strings
Is there any way to crop a text string to a certain length? i.e. [fictional] crop ($string, 40); would crop to the frist 40 characters?

Formatting Strings
I am currently using sprintf to format a report from a MySQL database data. I was wondering if there is an easy way to format text besides using sprintf. See below for the example I need to recreate. If any lines exceed the 75 column the need to wrap to the next line and indent 24 spaces. PHP Code:

Evaluating Strings...
In php, I have an array called "q". The elements are:

$q[0] = 2
$q[1] = 4
$q[2] = 5
$q[3] = 3

I'd like to be able to loop through this array via a While loop, and
echo the contents of these array elements back to the screen.

When I try something like:

for($i = 0; $i < 4; $i++) {
echo $q[i];
echo eval("$q[i]");
echo eval("$q[" . i . "]");
}

I get the "String" instead of the "Contents". For example, the output
is $q[0] instead of 2, $q[1] instead of 4, etc.

How To Connect 2 Strings Together With PHP
I know how to do it in Javascript but its not the same for PHP. What i am trying to do is connect 2 strings together. Like the string "index" and ".php". For javascript, id probably write it like this ...

name = "index";
name2 = ".php";
name3 = name + name2;

that would connect them and put them into one variable. I tried that with PHP but it didnt work.


Copyright © 2005-08 www.BigResource.com, All rights reserved