473,505 Members | 14,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding and updating text between parentheses with PHP4

1 New Member
In PHP4, how would I go about finding *every* instance of text (max of 14 characters) in a string that is placed within parentheses? And then loop through each instance and update the string accordingly.

Here's an example:

$myString = "Google's (GOOG) YouTube, Microsoft (MSFT) MSNBC and Viacom (VIA)";

The idea would be to take each stock symbol and insert a link like:

(<a href="http://finance.yahoo.com/q?s=goog">GOOG</a>)

...and then to do the same thing for the other symbols.

Any pointers would be appreciated.
Mar 26 '07 #1
1 1346
ronverdonk
4,258 Recognized Expert Specialist
Try this one. You can adapt it yourself to remove the parentheses from the result array.
[php]
<?php
$text = "Google's (GOOG) YouTube, Microsoft (MSFT) MSNBC and Viacom (VIA)";
$pattern = '(\((?:[^\(\)]+(?:"[^"]*"|\'[^\']*\')?)+\))';
preg_match_all($pattern, $text, $snip);
echo '<pre>'; print_r($snip);
?>[/php]

Ronald :cool:
Mar 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
1585
by: Steven Bethard | last post by:
I have a list of strings that looks something like: lst = The parentheses in the labels indicate where an "annotation" starts and ends. So for example, the label '(*)' at index 2 of the list...
3
1501
by: Jacob Weber | last post by:
If I do a search with a regular expression that uses parenthesized subexpressions, is there a way to find out where it found the subexpressions? For example, say I do: "bb".search(/b(.)/g); ...
0
935
by: Jeff | last post by:
I'm having a problem updating a DataGrid when using the grid's in-place editing features. I believe that my major problem is locating the row in the dataset that matches the row in the grid. Does...
1
1607
by: Peter Cruickshank | last post by:
Hi I'm trying to get some PHP4 code working on PHP5 - and am having an issue with a part of the code that uses html_doc() to turn html text scraped from a website into something that can be...
7
3423
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For...
9
7288
by: trihanhcie | last post by:
Hi, I would like to extract the text in an HTML file For the moment, I'm trying to get all text between <tdand </td>. I used a regular expression because i don't know the "format between...
12
2280
by: Drazen Gemic | last post by:
How long will PHP4 be supported ? When is PHP4 end of life scheduled ? DG
7
9064
by: Brad Baker | last post by:
I am trying to programmatically set a placeholder control in csharp which is nested inside a repeater control between <ItemTemplateand </ItemTemplate> tags, however I am running into problems. I've...
12
1856
by: Jeff | last post by:
As I'm learning PHP, I'm making a fair number of mistakes in syntax. In perl, you can turn on reading these errors from the browser by adding this: use CGI::Carp 'fatalsToBrowser'; Is there...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.