Jump to content

jpratt

Members
  • Posts

    144
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jpratt's Achievements

Member

Member (2/5)

0

Reputation

  1. This throws an error: Warning: preg_replace() [function.preg-replace]: Unknown modifier 'j' in C:\Program Files\reporting\Program\www\localhost\trans\import.php on line 20
  2. Now I tried this to replace the content with a placeholder but removes the script tags all together without making placeholders: $content = preg_replace('#<script type="text/javascript">(.*?)</script>#s',"$1[*SCRIPT*]$2",$content); Any ideas?
  3. Thanks, got it working. Here is the code for getting the script content into a simple array: if(preg_match_all('#<script type="text/javascript">(.*?)</script>#s', $content, $matches)) { $scriptarr = array(); for ($row = 1; $row < 2; $row++) { foreach($matches[$row] as $field) { $scriptarr[] = $field; } } }
  4. Looking at it, I am going to do a replace on all the content between the script tags to create a second set of placeholders. But first I need to store the content from between the tags in an array. How do you get everything from between two tags and store in a variable? I looked over everything on php.net but most are replace or match. Is there a way of giving it and expression and have it return the content that matched it? I think this is my expression: '/<\script>(.*?)<\/script>/'
  5. OK. I have this in another thread, but this is so specific and off the topic of the other thread I need to concentrate on this. I am placing content into an html structure. I have values in my database that have html stored. I am removing the content from the html string and placing placeholders to be filled with new content in another language. The only problem I have is in the content there is a script tag that is getting removed. This in turn creates an extra placeholder so the text ends up being placed in the wrong areas. The question is how do I exclude this one placeholder from being created? Here is the code for both creating the placeholder and placing content back into the string. // $content represents original content html string $content = $row['content']; // remove content and put in placeholders where the translated text is to go $content = preg_replace('~(>)(?!\s*<).*?(<|$)~s',"$1[*CONTENT*]$2",$content); //open file from translator and place numbered lines in array $file = "translated.rtf"; $fh = fopen($file, 'r'); $data = fread($fh, filesize($file)); fclose($fh); $array = explode("\n", $data); //title is in separate field, place first translated line in projects in the title field $x = 1; foreach($array as $a) { if($x == 1) { $title = substr($a, 4); } else { $a = substr($a, 4); $content = preg_replace('~\[\*CONTENT\*\]~',$a,$content,1); } $x++; } echo $content
  6. Any idea how I would handle the content in the script tags?
  7. That is awesome thanks. I am still learning about reg expressions, but you have helped out tons. Also last problem is the content between the script tags. No idea on how to ignore this when creating the content 'fields'.
  8. This works out great. There is only a few problems I am having. It is placing content area between 2 tags with no data. So if I have this: <img src='blah' align='right'><p>some text</p> It places a content area between the img tag and the opening p tag as well as where the true content is. Also Exporting was not a problem, because I could look at each chunk of text coming in, but I have <script> tags with content between them as well. Other than this I think we might have it about there.
  9. yep, thats what I want. The middle of the process is outputting a file for the translator, then getting it back and importing to get the result you described.
  10. OK here goes. The first step you helped with was getting the text out of the html. This I wrote to a file orginized like this: 1.1 First chunk of text from first page. blah blah blah 1.2 second chunk of text. blah blah blah 1.3 third chunk of text 2.1 First chunk of text from second page. blah blah blah 2.2 second chunk of text. blah blah blah 2.3 third chunk of text 2.4 could have additional text ... This file is given to the translator, and given back in the same format just another language. Now I have to stick the new language back into the html tags in the right place. I am not over writing text, just creating a new entry in the database with a different language key. So I was thinking of reading the english html string again and walking through the string placing the html and text in an array. if the element of the array is html it ignores it, but if it is text it replaces the english version in the array. Then when it is done, it writes the array to the database in a new row with the new language id.
  11. Sorry, after looking through things, your idea works great. Now I have to reverse engineer the thing. So the text has been taken out and changed to a different language. Now I have to stick it back in based on the english html. I was thinking of looping through the field sticking it into a 2 dimentional array. The first element would contain tags or text, the second would contain a 1 or 0 depending on if it was html or text. If it is text it is replaced with the new language for that section. We got the text to be separate from the html, but how do I get them all into an array together without just removing the html? Thanks.
  12. I dont want to go off new lines because some tags my be in the middle of the line such as b tags. I just need an expression to strip out all html tags and place the chunks of text between the tags in an array in the order they were encountered.
  13. I have tried various reg expressions trying to remove the html using preg_match_all with little or no success. Anyone know of a regular expression that will remove this?
  14. So my question is. How would I implement something like preg_match_all or fgetss to get me desired results. The first tag it hits might be an img tag an a tag a p tag or something else. How would I loop through the string to place the chunks of text in an array?
  15. I looked into the DOMDocument model and its isn't very dynamic. Some of my text will be in p tags, some in span tags and so forth. I just need something like the striptags function but instead of just removing all the tags and return all the text together, it needs to return an array of the chunks of text found between the tags in order they were encountered.
×
×
  • 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.